#include <bits/stdc++.h>
using namespace std;
int main() {
int n, q;
cin >> n >> q;
vector<int> v;
make_heap(v.begin(), v.end(), greater<int>());
for (int i = 0; i < n; i++) {
int x; cin >> x;
v.push_back(x);
push_heap(v.begin(), v.end(), greater<int>());
}
unordered_map<int, int> hash;
for (int i = 0; i < n; i++) {
hash[v[i]] = i + 1;
}
getchar();
while (q--) {
string s;
getline(cin, s);
stringstream ss(s);
vector<string> op;
string all = s;
while (ss >> s) {
op.push_back(s);
}
if (all.find("root") != string::npos) {
int x = stoi(op[0]);
cout << (hash[x] == 1 ? "T" : "F") << "\n";
} else if (all.find("siblings") != string::npos) {
int x = stoi(op[0]), y = stoi(op[2]);
cout << ((hash[x] / 2 == hash[y] / 2) ? "T" : "F") << "\n";
} else if (all.find("parent") != string::npos) {
int x = stoi(op[0]), y = stoi(op[5]);
cout << ((hash[y] / 2 == hash[x]) ? "T" : "F") << "\n";
} else if (all.find("child") != string::npos) {
int x = stoi(op[0]), y = stoi(op[5]);
cout << ((hash[x] / 2 == hash[y]) ? "T" : "F") << "\n";
}
}
return 0;
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 零经验选手,Compose 一天开发一款小游戏!
· 因为Apifox不支持离线,我果断选择了Apipost!
· 通过 API 将Deepseek响应流式内容输出到前端
2020-03-17 字符串的操作:字符串变换(蓝桥杯训练系统)
2020-03-17 递归+DP:爬楼梯问题
2020-03-17 (Good topic)哈希表:拼写单词 (3.17 leetcode每日打卡)