题目地址:http://acm.hrbeu.edu.cn/index.php?act=problem&id=1001&cid=51
#include <iostream>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <cstdio>
using namespace std;
typedef long long ll;
#define INF 0xfffffff
#define MAX(a,b) a>b?a:b
#define MIN(a,b) a>b?b:a
#define N 100001
int c[N],ma[N];
int lowbit(int t)
{
return t&(-t);
}
void insert(int k,int d,int max)
{
while(k<=max)
{
c[k]+=d;
k+=lowbit(k);
}
}
int getsum(int k)
{
int t=0;
while(k>0) //必须k>0,不能k为真。
{
t+=c[k];
k-=lowbit(k);
}
return t;
}
void swap(int &a,int &b)
{
int t=a;
a=b;
b=t;
}
int main()
{
int i,j,k,t;
int m,n;
while(cin>>n>>k)
{
memset(c,0,sizeof(c));
for(i=1;i<=n;i++)
{
insert(i,1,n);
ma[i]=1;
}
while(k--)
{
int a,b,f;
cin>>f>>a>>b;
if(f==0)
{
if(a>b) swap(a,b);
if(b==n&&a==1)
{
if(ma[n]==1)
{
c[n]--;
ma[n]=0;
}
else
{
c[n]++;
ma[n]=1;
}
}
else
{
if(ma[a]==1)
{
insert(a,-1,n);
ma[a]=0;
}
else
{
insert(a,1,n);
ma[a]=1;
}
}
}
else
{
if(a>b) swap(a,b);
int t1,t2,t3,t4;
t1=getsum(a-1);
t2=getsum(b-1);
int flag=0;
if(t2-t1==b-a)
{
flag=1;
cout<<"YES"<<endl;
}
if(!flag)
{
t3=getsum(n)-t2;
if(t3+t1==n-b+a)
{
flag=1;
cout<<"YES"<<endl;
}
else cout<<"NO"<<endl;
}
}
}//while
}//while
return 0;
}