记录编号 |
405593 |
评测结果 |
AAAAAAAAAA |
题目名称 |
人工湖 |
最终得分 |
100 |
用户昵称 |
kZime |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
0.202 s |
提交时间 |
2017-05-17 08:48:32 |
内存使用 |
0.31 MiB |
显示代码纯文本
# include <bits/stdc++.h>
# define MAXN 100023
# define mid ((l + r) >> 1)
using namespace std;
inline int gn() {
int k = 0;
char c = getchar();
for(; !isdigit(c); c = getchar());
for(; isdigit(c); c = getchar()) k = k * 10 + c - '0';
return k;
}
struct node {
bool tr;
node *ls, *rs;
inline node() {
ls = rs = NULL;
tr = 1;
}
}*root;
node *build(int l, int r) {
node *x = new node();
if(l + 1 == r) {
return x;
}
x->ls = build(l, mid);
x->rs = build(mid, r);
return x;
}
bool query(node *x, int l, int r, int s, int t) {
if(s == t) return 1;
if(l == s && t == r) return x->tr;
else if(t <= mid) return query(x->ls, l, mid, s, t);
else if(s >= mid) return query(x->rs, mid, r, s, t);
else return query(x->ls, l, mid, s, mid) && query(x->rs, mid, r, mid, t);
}
void change(node *x, int l, int r, int k) {
if(l + 1 == r) {
x->tr ^= 1;
} else {
if(k < mid) change(x->ls, l, mid, k);
else change(x->rs, mid, r, k);
x->tr = x->ls->tr && x->rs->tr;
}
}
int n, m;
bool flag = 1;
int main() {
freopen("lakee.in", "r", stdin);
freopen("lakee.out", "w", stdout);
n = gn();
m = gn();
root = build(1, n);
for(int i = 1; i <= m; i++) {
if(gn()) {
int s = gn();
int t = gn();
if(t < s) swap(s, t);
if(query(root, 1, n, s, t) || (flag && query(root, 1, n, 1, s) && query(root, 1, n, t, n))) printf("YES\n");
else printf("NO\n");
} else {
int s = gn();
int t = gn();
if(t < s) swap(s, t);
if(s == 1 && t == n) flag = !flag;
else change(root, 1, n, s);
}
}
}