https://www.patest.cn/contests/gplt/L3-016

题意:中文。

思路:暴力构造,暴力查询就好了。只不过操作很多,很麻烦。比赛的时候再给我10分钟就打完了,手速太慢好可惜。

 #include <bits/stdc++.h>
using namespace std;
#define N 100010
typedef long long LL;
struct Node {
int num;
Node *l, *r, *fa;
Node (int n) {
l = r = fa = NULL;
num = n;
}
} ;
Node *root;
int flag, d;
char s[][]; void Insert(Node *now, Node *f, int x, int kind) {
if(now == NULL) {
now = new Node(x);
now->fa = f;
if(kind) f->r = now;
else f->l = now;
return ;
}
if(x > now->num) Insert(now->r, now, x, );
else Insert(now->l, now, x, );
} Node *Find(int x) {
Node *now = root; d = ;
while(now != NULL && now->num != x) {
if(x > now->num) now = now->r;
else now = now->l;
d++;
}
return now;
} void Solve1(int x) {
if(root && root->num == x) flag = ;
} void Solve2(int x, int y) {
Node *now1 = Find(x), *now2 = Find(y);
if(now1 && now2 && now1->fa == now2->fa) flag = ;
} void Solve3(int x, int y) {
Node *now = Find(y);
if(now && now->fa && now->fa->num == x) flag = ;
} void Solve4(int x, int y) {
Node *now = Find(y);
if(now && now->l && now->l->num == x) flag = ;
} void Solve5(int x, int y) {
Node *now = Find(y);
if(now && now->r && now->r->num == x) flag = ;
} void Solve6(int x, int y) {
Node *now1 = Find(x);
int d1 = d;
Node *now2 = Find(y);
int d2 = d;
if(now1 && now2 && d1 == d2) flag = ;
} int main() {
int n, a, b; scanf("%d", &n);
if(n) scanf("%d", &a), root = new Node(a);
for(int i = ; i < n; i++) scanf("%d", &a), Insert(root, NULL, a, );
int q; scanf("%d", &q);
while(q--) {
flag = ;
scanf("%d", &a);
scanf("%s", s[]);
if(s[][] == 'a') {
scanf("%d", &b);
scanf("%s %s", s[], s[]);
if(s[][] == 's') {
Solve2(a, b);
} else {
Solve6(a, b);
scanf("%s %s %s", s[], s[], s[]);
}
} else {
scanf("%s %s", s[], s[]);
if(s[][] == 'o') {
Solve1(a);
} else if(s[][] == 'a') {
scanf("%s %d", s[], &b), Solve3(a, b);
} else if(s[][] == 'e') {
scanf("%s %s %d", s[], s[], &b), Solve4(a, b);
} else {
scanf("%s %s %d", s[], s[], &b), Solve5(a, b);
}
}
if(flag) puts("Yes");
else puts("No");
}
return ;
}
05-23 08:13