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 |
不知道为什么会内存超出//用树状数组做的,不知道为什么会超时 #include<iostream> #include<cstring> using namespace std; char c; int lowbit(int n) { return n&(-n); } void modify(int begina,int beginb,int enda,int endb,int **a) { int i,j; for(i=begina;i<=enda;i+=lowbit(i)) { for(j=beginb;j<=endb;j+=lowbit(j)) { if(a[i][j]==0) a[i][j]+=1; else a[i][j]-=1; } } } int sum(int i,int j,int **a) { int x,y; int result=0; for(x=i;x>=1;x-=lowbit(x)) { for(y=j;y>=1;y-=lowbit(y)) { result+=a[x][y]; } } // cout<<result; return result; } int main() { int n; cin>>n; while(n--) { int N,T,i,j; cin>>N>>T; int **p=new int *[N]; for(i=1;i<=N;i++) { p[i]=new int[T]; } for(i=1;i<=N;i++) { for(j=1;j<=N;j++) { p[i][j]=0; } } for(i=1;i<=N;i++) while(true) { cin>>c; if(c=='C') { int begina,beginb,enda,endb; cin>>begina>>beginb>>enda>>endb; modify(begina,beginb,enda,endb,p); T--; } else { cin>>i>>j; cout<<sum(i,j,p)<<endl; T--; } if(T==0)break; } delete[]p; if(n)cout<<endl; } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator