• 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
    ", ans[i]);
    82     return 0;
    83 }
    View Code
  • 相关阅读:
    Hive优化
    RDD
    从Hadoop MapReduce到Spark
    Spark on yarn模式
    Hive的web端配置——HWI
    Spark环境搭建
    java身份证号校验
    java手机号码、电子邮箱校验
    服务器运维的日常维护工作
    JavaSSM框架简介
  • 原文地址:https://www.cnblogs.com/y7070/p/5019017.html
Copyright © 2020-2023  润新知