| ||||||||||
| 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 | |||||||||
TLE半天了,大牛们帮忙看看吧,已经用了树状数组了#include <cstdlib>
#include <iostream>
using namespace std;
int matrix[1024*1024+1];
int lowbit(int i)
{
return i&(i^(i-1));
}
int main(int argc, char *argv[])
{
int a,n;
scanf("%d%d",&a,&n);
while(scanf("%d",&a))
{
if(a==3)
break;
else if(a==1)
{
int a,b,c;
scanf("%d%d%d",&a,&b,&c);
int x=a*n+b+1;
//change(n*n,a*n+b+1,c);
//void change(int a , int x , int y)
while(x<=n*n)
{
matrix[x]+= c;
x=x+lowbit(x);
}
}
else if(a==2)
{
int a,b,c,d,sum=0;
scanf("%d%d%d%d",&a,&b,&c,&d);
for(int i=a;i<=c;i++)
{
//sum+=getsum(b+i*n,d+i*n+1);
//int getsum(int x,int y)
int sumx=0,sumy=0;
int x=b+i*n,y=d+i*n+1;
while(x>0)
{
sumx+=matrix[x];
x=x-lowbit(x);
}
while(y>0)
{
sumy+=matrix[y];
y=y-lowbit(y);
}
sum+=sumy-sumx;
}
printf("%d\n",sum);
}
}
system("PAUSE");
return EXIT_SUCCESS;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator