#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
const int maxn = 1010;
vector<int> v;
int n, m;
void upAdjust(int i)
{
if(i == 1) return;
while(i != 1)
{
if(v[i] < v[i / 2])
{
swap(v[i], v[i / 2]);
i = i / 2;
}
else break;
}
}
bool judgeroot(int x)
{
if(x == v[1]) return true;
else return false;
}
bool judgebro(int a, int b)
{
int fa,fb;
for(int i = 1; i <= n; i++)
{
if(v[i] == a) fa = i;
}
for(int i = 1; i <= n; i++)
{
if(v[i] == b) fb = i;
}
if(fa/2 == fb/2) return true;
else return false;
}
bool judgepar(int a, int b)
{
int fa,fb;
for(int i = 1; i <= n; i++)
{
if(v[i] == a) fa = i;
}
for(int i = 1; i <= n; i++)
{
if(v[i] == b) fb = i;
}
if(fa == fb / 2) return true;
else return false;
}
bool judgechi(int a, int b)
{
int fa,fb;
for(int i = 1; i <= n; i++)
{
if(v[i] == a) fa = i;
}
for(int i = 1; i <= n; i++)
{
if(v[i] == b) fb = i;
}
// printf("fa = %d, fb = %d\n", fa,fb);
if( fa / 2 == fb) return true;
else return false;
}
int main()
{
int a,b;
cin >> n >> m;
string str;
v.resize(n + 1);
for(int i = 1; i <= n; i++)
{
cin >> v[i];
upAdjust(i);
}
while(m--)
{
cin >> a >> str;
if(str == "and") // and
{
cin >> b >> str >> str;
if(judgebro(a,b)) cout << "T" << endl;
else cout << "F" << endl;
}
else
{
cin >> str;
if(str == "a")
{
cin >> str >> str >> b;
if(judgechi(a,b)) cout << "T" << endl;
else cout << "F" << endl;
}
else
{
cin >> str;
if(str == "root")
{
if(judgeroot(a)) cout << "T" << endl;
else cout << "F" << endl;
}
else
{
cin >> str >> b;
if(judgepar(a,b)) cout << "T" << endl;
else cout << "F" << endl;
}
}
}
}
return 0;
}
L2-012 关于堆的判断 (25 分)
最新推荐文章于 2025-04-16 19:36:23 发布