#include #define LEFT(x) (2*x) #define RIGHT(x) (2*x+1) using namespace std; int st[200100], lazy[200100]; 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; } if(lazy[index]!=0){ 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(qleft <=left && right <= qright) { //lazy[index]=1; } 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[LEFT(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){ 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; return st[index]; } else if( st[index]==0 || st[index]==1){ *ql = left; *qr = right; return st[index]; } 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; } return tips; } 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; } return tipd; } } } 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); } else { cin>>l; val = query(st, n, l, &sta, &dr); cout<