Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- typedef long long ll;
- const int N = 1e5 + 7;
- int t[N];
- void upd(int p, int x) {
- for (; p < N; p = (p | (p + 1))) {
- t[p] += x;
- }
- }
- int sum(int p) {
- int res = 0;
- for (; p >= 0; p = (p & (p + 1)) - 1) {
- res += t[p];
- }
- return res;
- }
- int main() {
- ios::sync_with_stdio(0);
- cin.tie(0);
- vector <int> a = {1, 5, 2, 3, 2, 6};
- int n = (int) a.size();
- for (int i = 0; i < n; i++) {
- cout << sum(a[i] - 1) << ' ';
- upd(a[i], 1);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement