L2-013. 红色警报
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1000+10;
int v[maxn];
int sz = 1;
const int maxh = 20000+10;
int h[maxh];
const int TT = 10000;
void Insert(int vv)
{
int t = sz++;
v[t] = vv;
h[v[t]+TT] = t;
while(t > 1)
{
if(v[t] < v[t/2])
{
swap(v[t],v[t/2]);
swap(h[v[t/2]+TT],h[v[t]+TT]);
t /= 2;
}
else break;
}
}
int main(void)
{
int N,M;
cin>>N>>M;
for(int i= 0;i < N; ++i)
{
int a;
scanf("%d",&a);
Insert(a);
}
getchar();
while(M--)
{
bool yes = false;
string s;
getline(cin,s);
stringstream ss(s);
int a,b;
string S;
ss>>a;
ss>>S;
if(S == "and")
{
ss>>b;
a += TT;
b += TT;
if(h[a]/2 == h[b]/2)
yes = true;
}
else
{
ss>>S;
if(S == "a")
{
ss>>s;
ss>>s;
ss>>b;
a += TT;
b += TT;
if(h[a]/2 == h[b])
yes = true;
}
else {
ss >>S;
if(S == "root")
{
a += TT;
if(h[a] == 1)
yes = true;
}
else
{
ss>>S;
ss>>b;
a += TT;
b += TT;
if(h[a] == h[b]/2)
yes = true;
}
}
}
if(yes)
cout<<"T"<<endl;
else
cout<<"F"<<endl;
}
return 0;
}