-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHDU1166.cpp
More file actions
89 lines (76 loc) · 1.35 KB
/
HDU1166.cpp
File metadata and controls
89 lines (76 loc) · 1.35 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#include<cstring>
#include<iostream>
using namespace std;
#define M 50005
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
/*left,right,root,middle*/
int sum[M << 2];
inline void PushPlus(int rt)
{
sum[rt] = sum[rt << 1] + sum[rt << 1 | 1];
}
void Build(int l, int r, int rt)
{
if (l == r)
{
scanf("%d", &sum[rt]);
return;
}
int m = (l + r) >> 1;
Build(lson);
Build(rson);
PushPlus(rt);
}
void Updata(int p, int add, int l, int r, int rt)
{
if (l == r)
{
sum[rt] += add;
return;
}
int m = (l + r) >> 1;
if (p <= m)
Updata(p, add, lson);
else
Updata(p, add, rson);
PushPlus(rt);
}
int Query(int L, int R, int l, int r, int rt)
{
if (L <= l && r <= R)
{
return sum[rt];
}
int m = (l + r) >> 1;
int ans = 0;
if (L <= m)
ans += Query(L, R, lson);
if (R>m)
ans += Query(L, R, rson);
return ans;
}
int main()
{
freopen("input.txt", "r", stdin);
int T, n, a, b;
scanf("%d", &T);
for (int i = 1; i <= T; ++i)
{
printf("Case %d:\n", i);
scanf("%d", &n);
Build(1, n, 1);
char op[10];
while (scanf("%s", op) && op[0] != 'E')
{
scanf("%d %d", &a, &b);
if (op[0] == 'Q')
printf("%d\n", Query(a, b, 1, n, 1));
else if (op[0] == 'S')
Updata(a, -b, 1, n, 1);
else
Updata(a, b, 1, n, 1);
}
}
return 0;
}