-
Notifications
You must be signed in to change notification settings - Fork 0
/
mo.cpp
65 lines (56 loc) · 1.27 KB
/
mo.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
60
61
62
63
64
65
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
const int SQRT = (int)sqrt(N);
struct Query {
int l, r, bl, ix;
Query () {};
Query (int _l, int _r, int _ix) : l(_l), r(_r), bl(_l / SQRT), ix(_ix) {};
bool operator< (const Query& x) const {
return bl == x.bl ? (r < x.r) ^ (bl & 1) : bl < x.bl;
}
};
int a[N], ans[N], cnt[N], cntOfCnt[N], cur = 0;
void add(int x) {
int val = a[x];
--cntOfCnt[cnt[val]];
++cnt[val];
++cntOfCnt[cnt[val]];
if (cnt[val] > cur)
++cur;
}
void rem(int x) {
int val = a[x];
--cntOfCnt[cnt[val]];
if (cnt[val] == cur && cntOfCnt[cur] == 0)
--cur;
--cnt[val];
++cntOfCnt[cnt[val]];
}
void getAns(int i) {
ans[i] = cur;
}
int main() {
/*
int n, q;
scanf("%d %d", &n, &q);
forn(i, 0, n) scanf("%d", &a[i]);
vector<Query> qs(q);
forn(i, 0, q) {
int l, r;
scanf("%d %d", &l, &r);
qs[i] = Query(l, ++r, i);
}
sort(all(qs));
int l = 0, r = 0;
cntOfCnt[0] = N;
for (auto p : qs) {
while (l > p.l) add(--l);
while (r < p.r) add(r++);
while (l < p.l) rem(l++);
while (r > p.r) rem(--r);
getAns(p.ix);
}
forn(i, 0, q) printf("%d\n", ans[i]);
*/
}