Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
RE代码 求找错#include <cstdlib> #include <iostream> using namespace std; int n,len=1; struct _tree { int left,right,cnt,lazy; }; _tree t[3000000]; void init() { while(len<n) len*=2; for(int i=len;i<len+n;i++) { t[i].left=t[i].right=i-len+1; t[i].cnt=1; } for(int i=len+n;i<=2*len;i++) t[i].left=t[i].right=i-len+1; for(int i=len-1;i>=1;i--) { t[i].left=t[2*i].left; t[i].right=t[2*i+1].right; t[i].cnt=t[2*i].cnt|t[2*i+1].cnt; } } void change(int id,int left,int right,int c) { int tmp; if(t[id].left==left&&t[id].right==right) { t[id].lazy=1; t[id].cnt=1<<(c-1); tmp=id/2; while(tmp!=0) { t[tmp].cnt=t[2*tmp].cnt|t[2*tmp+1].cnt; tmp/=2; } return; } if(t[id].lazy!=0) { t[2*id].lazy=t[2*id+1].lazy=1; t[2*id].cnt=t[2*id+1].cnt=t[id].cnt; t[id].cnt=0; t[id].lazy=0; } if(t[2*id].right>=right) change(2*id,left,right,c); else if(t[2*id+1].left<=left) change(2*id+1,left,right,c); else { change(2*id,left,t[2*id].right,c); change(2*id+1,t[2*id+1].left,right,c); } } int query(int id,int left,int right) { if(t[id].left==left&&t[id].right==right) return t[id].cnt; if(t[id].lazy!=0) { t[2*id].lazy=t[2*id+1].lazy=1; t[2*id].cnt=t[2*id+1].cnt=t[id].cnt; t[id].cnt=0; t[id].lazy=0; } if(t[2*id].right>=right) return query(2*id,left,right); else if(t[2*id+1].left>=left) return query(2*id+1,left,right); else return query(2*id,left,t[2*id].right)|query(2*id+1,t[2*id+1].left,right); } int cnt(int x) { int sum=0; while(x!=0) { if(x%2==1) sum++; x/=2; } return sum; } int main(int argc, char* argv[]) { ios::sync_with_stdio(false); int a,t; char x; int y,z,l; cin>>n>>t>>a; init(); change(1,1,n,1); while(a--) { cin>>x; if(x=='C') { cin>>y>>z>>l; if(y>z) swap(y,z); change(1,y,z,l); } else if(x=='P') { cin>>y>>z; if(y>z) swap(y,z); cout<<cnt(query(1,y,z))<<endl; } } return EXIT_SUCCESS; } re了无限次,不知为何 Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator