记录编号 405543 评测结果 AAAAAAAAAA
题目名称 人工湖 最终得分 100
用户昵称 GravatarHeHe 是否通过 通过
代码语言 C++ 运行时间 0.196 s
提交时间 2017-05-16 21:43:57 内存使用 0.31 MiB
显示代码纯文本
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;

inline int in(void){ 
	char tmp = getchar();
	int res = 0;
	while(!isdigit(tmp)) tmp = getchar();
	while(isdigit(tmp))
		res = (res + (res <<2) << 1) + (tmp ^ 48), 
		tmp = getchar();
	return res;
}

struct NODE{
	bool flag;
	NODE *ls, *rs;

	NODE(){
		ls = rs = NULL;
		flag = true;
	}
};

NODE* build(int l, int r);
bool query(NODE *now, int l, int r, int L, int R);
void update(NODE *now, int l, int L, int R);

bool flag15 = true;
int N, Q;
int arg1, arg2, arg3;
NODE *root;

int main(){ 
#ifndef LOCAL
	freopen("lakee.in", "r", stdin);
	freopen("lakee.out", "w", stdout);
#else
	freopen("test.in", "r", stdin);
#endif
	N = in(), Q = in();
	
	root = build(1, N);

	for(int i = 1; i <= Q; ++i){ 
		arg1 = in(), arg2 = in(), arg3 = in();
		
		if(arg2 > arg3) arg2 ^= arg3 ^= arg2 ^= arg3;
		if(arg1){ 
			if(query(root, arg2, arg3, 1, N) || (flag15 && query(root, 1, arg2, 1, N) && query(root, arg3, N, 1, N)))
				printf("YES\n");
			else printf("NO\n");
		}
		else{
			if(arg2 == 1 && arg3 == 5) flag15 = !flag15;
			else update(root, arg2, 1, N);
		}
	}

	return 0;
}

NODE* build(int l, int r){
	NODE *p = new NODE();

	if((l + 1) ^ r){ 
		int mid = (l + r) >> 1;
		p->ls = build(l, mid);
		p->rs = build(mid, r);
	}

	return p;
}

bool query(NODE *now, int l, int r, int L, int R){ 
	if(l == r) return true;
	if(l == L && r == R) return now->flag;

	int mid = (L + R) >> 1;
	if(r <= mid) return query(now->ls, l, r, L, mid);
	if(mid <= l) return query(now->rs, l, r, mid, R);

	return query(now->ls, l, mid, L, mid) && query(now->rs, mid, r, mid, R);
}

void update(NODE *now, int l, int L, int R){
	if(L + 1 == R){ 
		now->flag = !now->flag;
		return ;
	}

	int mid = (L + R) >> 1;
	if(l < mid) update(now->ls, l, L, mid);
	else update(now->rs, l, mid, R);

	now->flag = now->ls->flag && now->rs->flag;

	return ;
}