-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAKVQLD03.cpp
More file actions
65 lines (59 loc) · 1.37 KB
/
AKVQLD03.cpp
File metadata and controls
65 lines (59 loc) · 1.37 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
// Created by rishabhstr ツ
#include <iostream>
#include <cstring> //memset
#include <algorithm>
#include <bitset>
#include <string>
#include <vector>
#include <utility>
#include <cstdio>
#include <queue>
#include <cmath>
#include <list>
#include <set>
#include <map>
using namespace std;
const int SIZE = 1e6;
int A[SIZE], tree[2*SIZE];
void update(int node, int start, int end, int idx, int val) {
if(start == end) {
A[idx] += val;
tree[node] += val;
}
else {
int mid = (start + end) / 2;
if(start <= idx && idx <= mid)
update(2*node, start, mid, idx, val);
else
update(2*node+1, mid+1, end, idx, val);
tree[node] = tree[2*node] + tree[2*node+1];
}
}
int query(int node, int start, int end, int l, int r) {
if(r < start || end < l)
return 0;
if(l <= start && end <= r)
return tree[node];
int mid = (start + end) / 2;
int p1 = query(2*node, start, mid, l, r);
int p2 = query(2*node+1, mid+1, end, l, r);
return (p1 + p2);
}
int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
#endif
std::ios::sync_with_stdio(false);
cin.tie(NULL);
int n, q, a, b;
string s;
cin >> n >> q;
while (q--) {
cin >> s >> a >> b;
if (s == "find")
cout << query(1, 1, n, a, b) << endl;
else if (a > 0 && b < n+1)
update(1, 1, n, a, b);
}
return 0;
}