Tsinsen-1487:分配游戏【树状数组】

  首先一定要看到x + y + z = N这个条件,没看到就世界再见了。

  赢的人得分需要大于等于2,那么无非就是 (x, y), (x, z), (y, z), (x, y, z) 大于其他的点。但是考虑一下(x, y, z)均大于是不可能的,因为 x + y + z = N。(x, y) 和 (x, z) 这样的也不可能同时大于一个点,那么符合条件的点,只能满足(x, y), (x, z), (y, z)其中之一,所以我们把每一个点拆分为3个点,分别投影到xOy, xOz, yOz平面上,然后需要处理的就是在一个二维平面内的指定点有多少个小于它了。

  二位树状数组肯定是可以的,但是空间需要为 n^2 ,无疑不可行,那么我们考虑固定一维,把查询和插入操作混在一起,给查询操作和插入操作标号,因为在同一个横坐标出,查询操作优先,所以我们把查询操作标号为0,插入操作标号为1。这样打包make_pair(x, op, y, self_id),直接使用pair的运算符即可。

 1 #include <bits/stdc++.h>
 2 #define rep(i, a, b) for (int i = a; i <= b; i++)
 3 #define REP(i, a, b) for (int i = a; i < b; i++)
 4 #define drep(i, a, b) for (int i = a; i >= b; i--)
 5 #define travel(x) for (int i = G[x]; i; i = E[i].nx) 
 6 #define mp make_pair
 7 #define pb push_back
 8 #define clr(x) memset(x, 0, sizeof(x))
 9 #define xx first
10 #define yy second
11 using namespace std;
12 typedef long long i64;
13 typedef pair<int, int> pii;
14 //********************************
15 const int maxn = 800005;
16 pair<int, pair<int, int> > sa[maxn];
17 pair<int, pair<int, int> > st[maxn];
18 pair<int, pair<int, pair<int, int> > > query[maxn << 1];
19 int top;
20 int hsh[(maxn << 1) * 3], cd;
21 int ans[maxn];
22 int c[(maxn << 1) * 3];
23 void Insrt(int x, int v) {
24     while (x <= cd) {
25         c[x] += v;
26         x += x & -x;
27     }
28 }
29 int Query(int x) {
30     int ret(0);
31     while (x > 0) {
32         ret += c[x];
33         x -= x & -x;
34     }
35     return ret;
36 }
37 int read() {
38     int l = 1, s(0); char ch = getchar();
39     while (ch < '0' || ch > '9') { if (ch == '-') l = -1; ch = getchar(); }
40     while (ch >= '0' && ch <= '9') { s = (s << 1) + (s << 3) + ch - '0'; ch = getchar(); }
41     return l * s;
42 }
43 int main() {
44     int N, m, T; N = read(), m = read(), T = read();
45     rep(i, 1, m) sa[i].xx = read(), sa[i].yy.xx = read(), sa[i].yy.yy = read(), hsh[++cd] = sa[i].xx, hsh[++cd] = sa[i].yy.xx, hsh[++cd] = sa[i].yy.yy;
46     rep(i, 1, T) st[i].xx = read(), st[i].yy.xx = read(), st[i].yy.yy = read(), hsh[++cd] = st[i].xx, hsh[++cd] = st[i].yy.xx, hsh[++cd] = st[i].yy.yy;
47     sort(hsh + 1, hsh + 1 + cd); cd = unique(hsh + 1, hsh + 1 + cd) - (hsh + 1);
48     rep(i, 1, m) {
49         sa[i].xx = lower_bound(hsh + 1, hsh + 1 + cd, sa[i].xx) - hsh;
50         sa[i].yy.xx = lower_bound(hsh + 1, hsh + 1 + cd, sa[i].yy.xx) - hsh;
51         sa[i].yy.yy = lower_bound(hsh + 1, hsh + 1 + cd, sa[i].yy.yy) - hsh;
52     }
53     rep(i, 1, T) {
54         st[i].xx = lower_bound(hsh + 1, hsh + 1 + cd, st[i].xx) - hsh;
55         st[i].yy.xx = lower_bound(hsh + 1, hsh + 1 + cd, st[i].yy.xx) - hsh;
56         st[i].yy.yy = lower_bound(hsh + 1, hsh + 1 + cd, st[i].yy.yy) - hsh;
57     }
58     rep(i, 1, m) query[++top] = mp(sa[i].xx, mp(1, mp(sa[i].yy.xx, i)));
59     rep(i, 1, T) query[++top] = mp(st[i].xx, mp(0, mp(st[i].yy.xx, i)));
60     sort(query + 1, query + 1 + top);
61     rep(i, 1, top) {
62         if (query[i].yy.xx == 0) ans[query[i].yy.yy.yy] += Query(query[i].yy.yy.xx - 1);
63         else Insrt(query[i].yy.yy.xx, 1);
64     }
65     memset(c, 0, sizeof(c)); top = 0;
66     rep(i, 1, m) query[++top] = mp(sa[i].xx, mp(1, mp(sa[i].yy.yy, i)));
67     rep(i, 1, T) query[++top] = mp(st[i].xx, mp(0, mp(st[i].yy.yy, i)));
68     sort(query + 1, query + 1 + top);
69     rep(i, 1, top) {
70         if (query[i].yy.xx == 0) ans[query[i].yy.yy.yy] += Query(query[i].yy.yy.xx - 1);
71         else Insrt(query[i].yy.yy.xx, 1);
72     }
73     memset(c, 0, sizeof(c)); top = 0;
74     rep(i, 1, m) query[++top] = mp(sa[i].yy.xx, mp(1, mp(sa[i].yy.yy, i)));
75     rep(i, 1, T) query[++top] = mp(st[i].yy.xx, mp(0, mp(st[i].yy.yy, i)));
76     sort(query + 1, query + 1 + top);
77     rep(i, 1, top) {
78         if (query[i].yy.xx == 0) ans[query[i].yy.yy.yy] += Query(query[i].yy.yy.xx - 1);
79         else Insrt(query[i].yy.yy.xx, 1);
80     }
81     rep(i, 1, T) printf("%d\n", ans[i]);
82     return 0;
83 }
View Code

 

posted @ 2015-12-04 13:05  y7070  阅读(194)  评论(0编辑  收藏  举报