blob: b3f97c8c656fc70ceda3f6ec5550c399236dc7fd (
plain)
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
|
#include <bits/stdc++.h>
using namespace std;
const int M = (1<<20);
const size_t size = M*2 + 10;
struct query {
char type;
union {
struct insert {
int p;
int x;
} insert;
struct sum {
int from;
int to;
} sum;
int del;
};
};
struct segtreePS {
int tree[size];
segtreePS() {
for (int i = 0; i < size; i++) tree[i] = 0;
}
void update(int where, int val) {
where += M;
while (where) {
tree[where] += val;
where /= 2;
}
}
int query(int from, int to) {
from += M;
to += M;
int ans = tree[from];
if (from != to) ans += tree[to];
while (from/2 != to/2) {
if (from % 2 == 0) ans += tree[from + 1];
if (to % 2 == 1) ans += tree[to - 1];
to /= 2; from /= 2;
}
return ans;
}
};
struct segtreeSP {
int tree[size];
segtreeSP() {
for (int i = 0; i < size; i++) tree[i] = 0;
}
void update(int from, int to, int val) {
from += M;
to += M;
tree[from] += val;
if (from != val) tree[to] += val;
while (from/2 != to/2) {
if (from % 2 == 0) tree[from + 1] += val;
if (to % 2 == 1) tree[to - 1] += val;
to /= 2; from /= 2;
}
}
int query(int where) {
int ans = 0;
where += M;
while (where) {
ans += tree[where];
where /= 2;
}
return ans;
}
};
vector<query> queries;
segtreeSP sptree;
map<int, int> q_to_pos;
int main() {
int n, inserts = 0;
scanf("%d", &n);
for (int i = 0; i < n; ++i) {
char c;
query q;
q.type = c;
scanf(" %c", &c);
if (c == 'D') {
int a;
cin >> a;
q.del = a;
}
else {
int a, b;
cin >> a >> b;
q.type = c;
if (c == 'I') {
q.insert = {a, b};
inserts++;
} else {
q.sum = {a, b};
}
}
queries.push_back(q);
}
for (int i = n-1; i > 0; i--) {
query q = queries[i];
if (q.type != 'I') continue;
int addition = sptree.query(q.insert.p);
q_to_pos[i] = addition + q.insert.p;
}
for (int i = 0; i < n; i++) {
}
}
|