-
Notifications
You must be signed in to change notification settings - Fork 0
/
2268.cpp
54 lines (43 loc) · 1.07 KB
/
2268.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
#include <iostream>
#include <algorithm>
#define N 1000005
using namespace std;
int n, m, a, b;
typedef long long ll;
ll arr[N * 9];
ll get(int left, int right, int index)
{
if (a <= left && right <= b)
return arr[index];
if (b < left || right < a)
return 0;
int mid = (left + right) / 2;
return get(left, mid, index * 2) + get(mid + 1, right, index * 2 + 1);
}
ll modify(int left, int right, int index)
{
if (left == right)
return arr[index] = b;
int mid = (left + right) / 2;
if (a <= mid)
return arr[index] = modify(left, mid, index * 2) + arr[index * 2 + 1];
return arr[index] = arr[index * 2] + modify(mid + 1, right, index * 2 + 1);
}
int main()
{
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
int i, c, temp;
scanf("%d %d", &n, &m);
for (i = 0; i < m; i++)
{
scanf("%d %d %d", &c, &a, &b);
if (c == 0){
if(a>b) swap(a,b);
printf("%lld\n", get(1, n, 1));
}
else
modify(1, n, 1);
}
return 0;
}