hrebu OJ 数据结构1001 人工湖的公路
http://acm.hrbeu.edu.cn/index.php?act=problem&id=1001&cid=19

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn = 100010;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
int ok[maxn<<2];
void build(int l,int r,int rt)
{
ok[rt]=1;
if(l==r) return ;
int m=(l+r)>>1;
build(lson);
build(rson);
}
void update(int L,int R,int l,int r,int rt)
{
if(L<=l&&r<=R){
ok[rt]^=1;
return ;
}
if(l==r) return ;
int m=(l+r)>>1;
if(L<=m) update(L,R,lson);
if(R>m) update(L,R,rson);
ok[rt]=ok[rt<<1] & ok[rt<<1|1];
}
bool query(int L,int R,int l,int r,int rt)
{
if(L>R) return true;
if(L<=l&&r<=R) return ok[rt];
int m=(l+r)>>1;
bool ans=true;
if(L<=m) ans&=query(L,R,lson);
if(R>m) ans&=query(L,R,rson);
return ans;
}
int main()
{
int n,m,f,x,y;
while(scanf("%d%d",&n,&m)!=EOF)
{
build(1,n,1);
while(m--)
{
scanf("%d%d%d",&f,&x,&y);
if(x>y) swap(x,y);
if(f==0)
{
if(x==y) continue;
if(y-x>1) update(y,y,1,n,1);
update(x,x,1,n,1);
}
else
{
bool ans=query(x,y-1,1,n,1)|query(1,x-1,1,n,1)&query(y,n,1,n,1);
if(ans) printf("YES\n");
else printf("NO\n");
}
}
}
}
关于那个更新操作,一直想不通,题目也没讲清楚