-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmos.cpp
More file actions
58 lines (56 loc) · 1.01 KB
/
mos.cpp
File metadata and controls
58 lines (56 loc) · 1.01 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
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
template<typename T>
struct MOS{
tree<pair<T, int>, null_type, less<pair<T, int>>, rb_tree_tag,tree_order_statistics_node_update> os;
map<T, int> cnt;
int size(){
return os.size();
}
int order_of_key(const T &x){
return os.order_of_key({x, 0});
}
int ge(int x){
return os.size() - order_of_key(x);
}
void insert(const T &x){
os.insert({x, cnt[x]++});
}
void erase(const T &x){
os.erase({x, --cnt[x]});
}
};
struct MOS{
int fen[maxn], sz, q[maxn];
int size(){
return sz;
}
int order_of_key(int p){
int ans = 0;
for(; p; p ^= p & -p)
ans += fen[p];
return ans;
}
int bigger(int x){
return sz - order_of_key(x);
}
void insert(int p){
q[sz++] = p;
for(p++; p < maxn; p += p & -p)
fen[p]++;
}
void erase(int p){
for(p++; p < maxn; p += p & -p)
fen[p]--;
sz--;
}
void reset(int p){
for(p++; p < maxn; p += p & -p)
fen[p] = 0;
}
void reset(){
while(sz)
reset(q[--sz]);
}
};