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
| #include <cstdio>
using namespace std; const int N = 15000, X = 32002; int ans[N], tree[X << 2]; int n, x, y;
void update(int p, int l, int r, int x) { if (l == r) { ++tree[p]; return; } int mid = l + r >> 1; if (x <= mid) update(p * 2, l, mid, x); else update(p * 2 + 1, mid + 1, r, x); tree[p] = tree[p * 2] + tree[p * 2 + 1]; }
int query(int p, int l, int r, int i, int j) { if (i <= l && r <= j) return tree[p]; int mid = l + r >> 1, sum = 0; if (i <= mid) sum += query(p * 2, l, mid, i, j); if (j > mid) sum += query(p * 2 + 1, mid + 1, r, i, j); return sum; }
int main() { scanf("%d", &n); for (int i = 0; i < n; ++i) { scanf("%d%d", &x, &y); ++x; ++ans[query(1, 1, X - 1, 1, x)]; update(1, 1, X - 1, x); } for (int i = 0; i < n; ++i) printf("%d\n", ans[i]); return 0; }
|