#include #define LEFT(x) (2*x) #define RIGHT(x) (2*x+1) using namespace std; int st[300100], lazy[300100]; void updateRangeRec(int* st, int left, int right, int qleft, int qright, int index){ if( right < qleft || left > qright ) return; if(left==right){ if(lazy[index]==1) lazy[index]=0; else st[index]=1-st[index]; return; } bool ok=false; if(lazy[index]!=0){ lazy[index]=0; lazy[LEFT(index)] = 1-lazy[LEFT(index)]; lazy[RIGHT(index)] = 1-lazy[RIGHT(index)]; ok=true; } if(qleft <=left && right <= qright) { if(!ok) lazy[index] = 1-lazy[index]; /* lazy[LEFT(index)] = 1-lazy[LEFT(index)]; lazy[RIGHT(index)] = 1-lazy[RIGHT(index)]; */ return; } if( (left <=qleft && qleft <=right) || (qright<=right && qright>=left ) ){ int mid = (left + right)/2; updateRangeRec(st, left, mid, qleft, qright, LEFT(index)); updateRangeRec(st, mid+1, right, qleft, qright, RIGHT(index)); } if(left!=right){ if(st[LEFT(index)]!=2 &&st[RIGHT(index)]!=2){ if( (st[LEFT(index)] + lazy[LEFT(index)])%2 == 0 && (st[RIGHT(index)] + lazy[RIGHT(index)])%2==0 ){ st[index]=0; } else if( (st[LEFT(index)] + lazy[LEFT(index)])%2== 1 && (st[RIGHT(index)]+ lazy[RIGHT(index)])%2 == 1){ st[index]=1; } else st[index]=2; } else{ st[index]=2; } } } void updateRange(int* st, int n, int qleft, int qright){ updateRangeRec(st, 1, n, qleft, qright, 1); } int queryRec(int *st, int pos, int left, int right, int* ql, int* qr, int index){ int val; /* if(lazy[index]!=0){ if(left!=right){ lazy[LEFT(index)] = 1-lazy[LEFT(index)]; lazy[RIGHT(index)] = 1-lazy[RIGHT(index)]; if( st[index]==0 || st[index]==1 ){ st[index] = (st[index]==0 + lazy[index])%2; } } lazy[index]=0; } */ if(left==right) { *ql=left; *qr = left; val= (st[index]+lazy[index])%2; } else if( st[index]==0 || st[index]==1){ *ql = left; *qr = right; val= (st[index]+lazy[index])%2; } else{ int qsts, qdrs, qstd, qdrd; int tips, tipd; int mid=(left+right)/2; if(pos <=mid){ tips = queryRec(st, pos, left, mid, &qsts, &qdrs, LEFT(index)); if(qdrs == mid){ tipd = queryRec(st, pos, mid+1, right, &qstd, &qdrd, RIGHT(index)); if(tipd ==tips){ *ql = qsts; *qr = qdrd; } else{ *ql = qsts; *qr = qdrs; } } else{ *ql = qsts; *qr = qdrs; } val= (tips+lazy[index])%2; } else{ tipd = queryRec(st, pos, mid+1, right, &qstd, &qdrd, RIGHT(index)); if(qstd == mid+1){ tips = queryRec(st, pos, left, mid, &qsts, &qdrs, LEFT(index)); if(tipd ==tips){ *ql = qsts; *qr = qdrd; } else{ *ql = qstd; *qr = qdrd; } } else{ *ql = qstd; *qr = qdrd; } val= (tipd+lazy[index])%2; } } /* Done: if(left!=right){ if(st[LEFT(index)]!=2 &&st[RIGHT(index)]!=2){ if( (st[LEFT(index)] + lazy[LEFT(index)])%2 == 0 && (st[RIGHT(index)] + lazy[RIGHT(index)])%2==0 ){ st[index]=0; } else if( (st[LEFT(index)] + lazy[LEFT(index)])%2== 1 && (st[RIGHT(index)]+ lazy[LEFT(index)])%2 == 1){ st[index]=1; } else st[index]=2; } else{ st[index]=2; } } */ return val; } int query(int *st, int n,int pos, int* sta, int* dr){ return queryRec(st, pos, 1, n, sta, dr, 1); } int main() { int n, m; cin>>n>> m; int o, l, r; int val, sta, dr; while(m--){ cin>>o; if(o==1){ cin>>l>>r; updateRange(st, n, l, r); /*int p=1,q=1; for(int i=1; i<2*n; i++){ cout<>l; val = query(st, n, l, &sta, &dr); cout<