-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcoci_2008_r6.cpp
59 lines (55 loc) · 1.28 KB
/
coci_2008_r6.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
#include<bits/stdc++.h>
using namespace std;
#define LSB(i) ((i) & -(i))
typedef long long ll;
struct FT {
std::vector<ll> data;
FT(ll size) {
data.resize(size+1);
}
void insert(ll idx, ll value) {
while(idx < data.size()) {
data[idx] += value;
idx += LSB(idx);
}
}
ll rsq(ll from, ll to) {
return getSum(to) - getSum(from-1);
}
ll getSum(ll elem) {
ll value = 0;
while(elem != 0) {
value += data[elem];
elem = elem & (elem - 1);
}
return value;
}
ll accessSingle(ll idx) {
ll sum = data[idx];
if(idx > 0) {
ll z = idx - (idx & -idx);
idx--;
while (idx != z) {
sum -= data[idx];
idx -= (idx & -idx);
}
}
return sum;
}
};
int old[100001];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
struct FT flowers(100001);
for(int i = 0; i < n; i++) {
int l,r;
cin >> l >> r;
int vl = flowers.getSum(l), vr = flowers.getSum(r);
cout << (vl + vr - old[l] - old[r]) << "\n";
old[l] = vl; old[r] = vr;
flowers.insert(l+1, 1); flowers.insert(r, -1);
}
}