-
Notifications
You must be signed in to change notification settings - Fork 34
/
1112-Curious-Robin-Hood.cpp
96 lines (72 loc) · 1.13 KB
/
1112-Curious-Robin-Hood.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
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
90
91
#include <iostream>
#define SIZE 100005
#include <string.h>
#include <stdio.h>
using namespace std;
int a[SIZE];
int n;
long long update(int i, int val)
{
while(i <= n) {
a[i] = a[i] + val;
i = i + (i & (-i));
}
}
long long query(int i)
{
long long ans;
ans = 0;
while(i > 0) {
ans = ans + a[i];
i = i - (i & (-i));
}
return ans;
}
int main()
{
int t;
int x;
int y;
int w;
int choice;
long long ans;
int q;
int ch;
scanf("%d", &t);
for (int cs = 1; cs <= t; cs++) {
scanf("%d", &n);
scanf("%d", &q);
memset(a, 0, sizeof a);
for (int i = 1; i <= n; i++) {
scanf("%d", &x);
update(i, x);
}
printf("Case %d:\n", cs);
for (int i = 0; i < q; i++) {
scanf("%d", &ch);
switch(ch) {
case 1:
scanf("%d", &x);
x++;
ans = query(x) - query(x-1);
update(x, -ans);
printf("%lld\n", ans);
break;
case 2:
scanf("%d", &x);
x++;
scanf("%d", &w);
update(x, w);
break;
case 3:
scanf("%d", &x);
scanf("%d", &y);
x++;
y++;
ans = query(y) - query(x -1);
printf("%lld\n", ans);
break;
}
}
}
}