题目:http://acm.hdu.edu.cn/showproblem.php?pid=1166
代码LTE了,看了下Discuss是说要用线段树,先按下不表,贴下自己LTE的代码。正确答案正在探索中,以后再编辑。
9528873 | Time Limit Exceeded | 1166 | 1000MS | 388K | 859 B | G++ |
#include<cstdio>
#include<cstring>
#include<numeric>
using namespace std;
int arr[50010];
int main()
{
int T, N;
char cmd[10];
//freopen("in.txt", "r", stdin);
scanf("%d", &T);
for(int i=0; i<T;++i)
{
scanf("%d", &N);
for(int j = 1; j <= N; ++j)
scanf("%d", arr+j);
int x, y;
printf("Case %d:\n", i+1);
while(scanf("%s", cmd) && strcmp(cmd, "End"))
{
getchar();
scanf("%d %d", &x, &y);
if(!strcmp(cmd, "Query"))
{
printf("%d\n", accumulate(arr+x, arr+y+1, 0));
}
else if(!strcmp(cmd, "Add"))
{
arr[x] += y;
}
else if(!strcmp(cmd, "Sub"))
{
arr[x] -= y;
}
}
}
return 0;
}