this is my code ---------------------------------------------- #include<iostream> #include<vector> #include<string.h> using namespace std; vector<int> tbf(1000000,0),array(1000000,0); //vector 'tbf' denotes tobeflipped void make(int ptr,int b,int e) { if(b==e) { array[ptr]=0; return; } int mid=(b+e)/2; make(ptr*2,b,mid); make(ptr*2+1,mid+1,e); array[ptr]=array[2*ptr]+array[2*ptr+1]; //combine } int query(int ptr,int b,int e,int i,int j) { if(j<b || i>e) return 0; if(tbf[ptr]&1) { array[ptr]=(e-b+1)-array[ptr]; tbf[2*ptr]+=tbf[ptr]; tbf[2*ptr+1]+=tbf[ptr]; tbf[ptr]=0; } if(b>=i && e<=j) return array[ptr]; int mid=(b+e)/2; int x=query(2*ptr,b,mid,i,j)+query(2*ptr+1,mid+1,e,i,j); return x; } void update(int ptr,int b,int e,int i,int j) { if(j<b || i>e) return; if(tbf[ptr]&1) { array[ptr]=(e-b+1)-array[ptr]; tbf[2*ptr]+=tbf[ptr]; tbf[2*ptr+1]+=tbf[ptr]; tbf[ptr]=0; } if(b>=i && e<=j) { array[ptr]=(e-b+1)-array[ptr]; tbf[2*ptr]+=1; tbf[2*ptr+1]+=1; tbf[ptr]=0; return; } int mid=(b+e)/2; update(2*ptr,b,mid,i,j); update(2*ptr+1,mid+1,e,i,j); if(!tbf[2*ptr] && !tbf[2*ptr+1]) array[ptr]=array[2*ptr]+array[2*ptr+1]; else if(tbf[ptr*2] && tbf[2*ptr+1]) array[ptr]=(mid-b+1-array[2*ptr])+(e-mid-array[2*ptr+1]); else if(!tbf[2*ptr]) array[ptr]=array[2*ptr]+(e-mid-array[2*ptr+1]); else array[ptr]=(mid-b+1-array[2*ptr])+array[2*ptr+1]; } int main() { int n,q,st,en,opt; cin>>n>>q; make(1,1,n); for(int i=0;i<q;i++) { cin>>opt>>st>>en; //st++; //en++; if(opt==0) update(1,1,n,st,en); else cout<<query(1,1,n,st,en)<<"\n"; /* cout<<"state of the array[]\n------------\n"; for(int i=1;i<=7;i++) cout<<array[i]<<"\t"; cout<<"\n"; cout<<"\nstate of the tbf[]\n------------\n"; for(int i=1;i<=7;i++) cout<<tbf[i]<<"\t"; cout<<"\n--------------\n";*/ } } ---------------------------------------------------------------------------------------- getting WA.. help me debugging
-- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.