-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path3468.cpp
60 lines (58 loc) · 1.27 KB
/
3468.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include <cstdio>
#include <cstdlib>
#include <cstring>
//#define B 2//记得这样调试~~
#define B 300
using namespace std;
int A[100008],N;
long long bucket[400],addv[400];
int num(int i)
{
return (i-1)/B+1;
}
int main()
{
int Q;
scanf("%d%d",&N,&Q);
for(int i=1;i<=N;++i)
scanf("%d",&A[i]);
for(int i=1;i<=N;++i)
bucket[num(i)]+=A[i];
for(int i=1;i<=Q;++i)
{
char ch;
int a,b,x;
scanf(" %c %d%d",&ch,&a,&b);
if(ch=='C')
{
scanf("%d",&x);
for(;a<=b && (a-1)%B!=0;++a)
{
A[a]+=x;
bucket[num(a)]+=x;
}
for(;a<=b && b%B!=0;--b)
{
A[b]+=x;
bucket[num(b)]+=x;
}
for(int j=a;j<=b;j+=B)
{
bucket[num(j)]+=x*B;
addv[num(j)]+=x;
}
}
else
{
long long result=0;
for(;a<=b && (a-1)%B!=0;++a)
result+=A[a]+addv[num(a)];
for(;a<=b && b%B!=0;--b)//--b
result+=A[b]+addv[num(b)];
for(;a<=b;a+=B)
result+=bucket[num(a)];
printf("%I64d\n",result);
}
}
return 0;
}