代码及其注释:
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <sstream>
#include <iterator>
#include <map>
#include <set>
#include <stack>
#include <queue>
using namespace std;
stringstream ss;
typedef long long ll;
map<int, int> mp;
const int N = 10010;
int n, m, cnt, head, h[N];
void create(int x){//堆的建立
h[++cnt] = x;
int t = cnt;
while(t > 1 && h[t/2] > h[t])
{
swap(h[t/2],h[t]);
t/=2;
}
h[t] = x;
}
int main(){
cin >> n >> m;
for(int i = 1; i<= n; i ++){
cin>>head;
create(head);
}
// 用mp记录每个元素的下标, 利用堆是完全二叉树的性质即可判断语句正确性
for(int i = 1; i <= n; i ++) mp[h[i]] = i;
// 因为语句固定, 可通过分开输入字符串来进行一句语句的输入
while(m -- )
{
int a , b = 0;
string s;
cin>>a>>s;
if(s[0] == 'a')
{
cin>>b>>s>>s;
if(mp[a]/2 == mp[b]/2) cout<<"T"<<endl;
else cout<<"F"<<endl;
}else
{
cin>>s>>s;
if(s[0] == 'r')
{
if(mp[a] == 1) cout<<"T"<<endl;
else cout<<"F"<<endl;
}else
{
if(s[0] == 'p'){
cin>>s>>b;
if(mp[b]/2 == mp[a]) cout<<"T"<<endl;
else cout<<"F"<<endl;
}else{
cin>>s>>b;
if(mp[a]/2 == mp[b]) cout<<"T"<<endl;
else cout<<"F"<<endl;
}
}
}
}
}