Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const int maxn = 1 << 20, mask = maxn-1;
- int t[maxn];
- void add(int v)
- {
- while (v & mask) {
- t[v] += 1;
- v = (v | (v-1)) + 1;
- }
- }
- int sum(int v)
- {
- int s = 0;
- while (v & mask)
- {
- s += t[v];
- v = v & (v-1);
- }
- return s;
- }
Add Comment
Please, Sign In to add comment