-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSQRT decomp.cpp
More file actions
64 lines (57 loc) · 1.39 KB
/
SQRT decomp.cpp
File metadata and controls
64 lines (57 loc) · 1.39 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
struct query{
int l, r, d, idx;
inline query() {}
inline query(int a, int b, int c){
idx = c;
l = a, r = b, d = l / block_size;
}
inline bool operator < (const query& other) const{
if (d != other.d) return (d > other.d);
return ((d & 1) ? (r < other.r) : (r > other.r));
}
} Q[MAX];
for (i = 0; i < q; i++){
l = fastio::number();
r = fastio::number();
l--, r--;
Q[i] = query(l, r, i);
}
sort(Q, Q + q);
a = 0, b = 0, xx = 0, res = 0;
for (i = 0; i < q; i++){
l = Q[i].l, r = Q[i].r;
while (a > l) insert(--a);
while (b <= r) insert(b++);
while (a < l) erase(a++);
while (b > (r + 1)) erase(--b);
out[Q[i].idx] = res ^ xx;
}
////////////////////////////
add(position):
count[array[position]]++
if count[array[position]] == 3:
answer++
remove(position):
count[array[position]]--
if count[array[position]] == 2:
answer--
currentL = 0
currentR = 0
answer = 0
count[] = 0
for each query:
// currentL should go to L, currentR should go to R
while currentL &lt; L:
remove(currentL)
currentL++
while currentL &gt; L:
add(currentL)
currentL--
while currentR &lt; R:
add(currentR)
currentR++
while currentR &gt; R:
remove(currentR)
currentR--
output answer
//////////////////////////////////////