# BZOJ3262 陌上花开

 1 /**************************************************************
2     Problem: 3262
3     User: rausen
4     Language: C++
5     Result: Accepted
6     Time:1356 ms
7     Memory:5888 kb
8 ****************************************************************/
9
10 #include <cstdio>
11 #include <algorithm>
12
13 #define lowbit(x) x & -x
14 using namespace std;
15 const int N = 100005;
16
17 struct data {
18     int a, b, c, s, ans;
19 }a[N], p[N];
20 inline bool sort1_cmp (const data &a, const data &b) {
21     return a.a == b.a ? (a.b == b.b ? a.c < b.c : a.b < b.b) : a.a < b.a;
22 }
23 inline bool operator < (const data &a, const data &b) {
24     return a.b == b.b ? a.c < b.c : a.b < b.b;
25 }
26 inline bool operator == (const data &a, const data &b) {
27     return a.a == b.a && a.b == b.b && a.c == b.c;
28 }
29 inline bool operator != (const data &a, const data &b) {
30     return !(a == b);
31 }
32
33 int tot, n, m, BIT[N << 1], ans[N];
34
36     int x = 0;
37     char ch = getchar();
38     while (ch < '0' || '9' < ch)
39         ch = getchar();
40     while ('0' <= ch && ch <= '9') {
41         x = x * 10 + ch - '0';
42         ch = getchar();
43     }
44     return x;
45 }
46
47 inline void update(int x, int del) {
48     while (x <= m)
49         BIT[x] += del, x += lowbit(x);
50 }
51
52 inline int query(int x) {
53     int res = 0;
54     while (x)
55         res += BIT[x], x -= lowbit(x);
56     return res;
57 }
58
59 void work(int l, int r) {
60     if (l == r) return;
61     int mid = l + r >> 1, i, j;
62     work(l, mid), work(mid + 1, r);
63     sort(p + l, p + mid + 1), sort(p + mid + 1, p + r + 1);
64     for (i = l, j = mid + 1; j <= r; ++j) {
65         for (; i <= mid && p[i].b <= p[j].b; ++i)
66             update(p[i].c, p[i].s);
67         p[j].ans += query(p[j].c);
68     }
69     for (j = l; j < i; ++j)
70         update(p[j].c, -p[j].s);
71 }
72
73 int main() {
74     int i, cnt;
76     for (i = 1; i <= tot; ++i)
78     sort(a + 1, a + tot + 1, sort1_cmp);
79     for (cnt = 1, i = 1; i <= tot; ++i, ++cnt)
80         if (a[i] != a[i + 1]) {
81             p[++n] = a[i];
82             p[n].s = cnt;
83             cnt = 0;
84         }
85     work(1, n);
86     for (i = 1; i <= n; ++i)
87         ans[p[i].ans + p[i].s - 1] += p[i].s;
88     for (i = 0; i < tot; ++i)
89         printf("%d\n", ans[i]);
90     return 0;
91 }
View Code

By Xs酱~ 转载请说明 博客地址：http://www.cnblogs.com/rausen
posted on 2014-11-23 16:55  Xs酱~  阅读(171)  评论(0编辑  收藏  举报