首先一定要看到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的运算符即可。

 #include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define REP(i, a, b) for (int i = a; i < b; i++)
#define drep(i, a, b) for (int i = a; i >= b; i--)
#define travel(x) for (int i = G[x]; i; i = E[i].nx)
#define mp make_pair
#define pb push_back
#define clr(x) memset(x, 0, sizeof(x))
#define xx first
#define yy second
using namespace std;
typedef long long i64;
typedef pair<int, int> pii;
//********************************
const int maxn = ;
pair<int, pair<int, int> > sa[maxn];
pair<int, pair<int, int> > st[maxn];
pair<int, pair<int, pair<int, int> > > query[maxn << ];
int top;
int hsh[(maxn << ) * ], cd;
int ans[maxn];
int c[(maxn << ) * ];
void Insrt(int x, int v) {
while (x <= cd) {
c[x] += v;
x += x & -x;
}
}
int Query(int x) {
int ret();
while (x > ) {
ret += c[x];
x -= x & -x;
}
return ret;
}
int read() {
int l = , s(); char ch = getchar();
while (ch < '' || ch > '') { if (ch == '-') l = -; ch = getchar(); }
while (ch >= '' && ch <= '') { s = (s << ) + (s << ) + ch - ''; ch = getchar(); }
return l * s;
}
int main() {
int N, m, T; N = read(), m = read(), T = read();
rep(i, , 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;
rep(i, , 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;
sort(hsh + , hsh + + cd); cd = unique(hsh + , hsh + + cd) - (hsh + );
rep(i, , m) {
sa[i].xx = lower_bound(hsh + , hsh + + cd, sa[i].xx) - hsh;
sa[i].yy.xx = lower_bound(hsh + , hsh + + cd, sa[i].yy.xx) - hsh;
sa[i].yy.yy = lower_bound(hsh + , hsh + + cd, sa[i].yy.yy) - hsh;
}
rep(i, , T) {
st[i].xx = lower_bound(hsh + , hsh + + cd, st[i].xx) - hsh;
st[i].yy.xx = lower_bound(hsh + , hsh + + cd, st[i].yy.xx) - hsh;
st[i].yy.yy = lower_bound(hsh + , hsh + + cd, st[i].yy.yy) - hsh;
}
rep(i, , m) query[++top] = mp(sa[i].xx, mp(, mp(sa[i].yy.xx, i)));
rep(i, , T) query[++top] = mp(st[i].xx, mp(, mp(st[i].yy.xx, i)));
sort(query + , query + + top);
rep(i, , top) {
if (query[i].yy.xx == ) ans[query[i].yy.yy.yy] += Query(query[i].yy.yy.xx - );
else Insrt(query[i].yy.yy.xx, );
}
memset(c, , sizeof(c)); top = ;
rep(i, , m) query[++top] = mp(sa[i].xx, mp(, mp(sa[i].yy.yy, i)));
rep(i, , T) query[++top] = mp(st[i].xx, mp(, mp(st[i].yy.yy, i)));
sort(query + , query + + top);
rep(i, , top) {
if (query[i].yy.xx == ) ans[query[i].yy.yy.yy] += Query(query[i].yy.yy.xx - );
else Insrt(query[i].yy.yy.xx, );
}
memset(c, , sizeof(c)); top = ;
rep(i, , m) query[++top] = mp(sa[i].yy.xx, mp(, mp(sa[i].yy.yy, i)));
rep(i, , T) query[++top] = mp(st[i].yy.xx, mp(, mp(st[i].yy.yy, i)));
sort(query + , query + + top);
rep(i, , top) {
if (query[i].yy.xx == ) ans[query[i].yy.yy.yy] += Query(query[i].yy.yy.xx - );
else Insrt(query[i].yy.yy.xx, );
}
rep(i, , T) printf("%d\n", ans[i]);
return ;
}

Tsinsen-1487:分配游戏【树状数组】的更多相关文章

  1. 【BZOJ4881】5月月赛D 线段游戏 树状数组+set

    Description quailty和tangjz正在玩一个关于线段的游戏.在平面上有n条线段,编号依次为1到n.其中第i条线段的两端点坐 标分别为(0,i)和(1,p_i),其中p_1,p_2,. ...

  2. 【bzoj4881】[Lydsy2017年5月月赛]线段游戏 树状数组+STL-set

    题目描述 quailty和tangjz正在玩一个关于线段的游戏.在平面上有n条线段,编号依次为1到n.其中第i条线段的两端点坐标分别为(0,i)和(1,p_i),其中p_1,p_2,...,p_n构成 ...

  3. HDU 5465 Clarke and puzzle Nim游戏+二维树状数组

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5465 Clarke and puzzle  Accepts: 42  Submissions: 26 ...

  4. 【Tsinsen A1339】JZPLCM (树状数组)

    Description 原题链接 ​ 给定一长度为\(~n~\)的正整数序列\(~a~\),有\(~q~\)次询问,每次询问一段区间内所有数的\(~LCM~\)(即最小公倍数).由于答案可能很大,输出 ...

  5. bzoj 4372 烁烁的游戏——动态点分治+树状数组

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=4372 和 bzoj 3070 震波 是一个套路.注意区间修改的话,树状数组不能表示 dis ...

  6. bzoj 4372 烁烁的游戏 —— 动态点分治+树状数组

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=4372 本以为和 bzoj3730 一样,可以直接双倍经验了: 但要注意一下,树状数组不能查询 ...

  7. BZOJ 1103: [POI2007]大都市meg [DFS序 树状数组]

    1103: [POI2007]大都市meg Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 2221  Solved: 1179[Submit][Sta ...

  8. 树形DP+DFS序+树状数组 HDOJ 5293 Tree chain problem(树链问题)

    题目链接 题意: 有n个点的一棵树.其中树上有m条已知的链,每条链有一个权值.从中选出任意个不相交的链使得链的权值和最大. 思路: 树形DP.设dp[i]表示i的子树下的最优权值和,sum[i]表示不 ...

  9. 树状数组---Squared Permutation

    BNUOJ   51636 最近,无聊的过河船同学在玩一种奇怪的名为“小Q的恶作剧”的纸牌游戏. 现在过河船同学手有张牌,分别写着,打乱顺序之后排成一行,位置从左往右按照标号. 接下来小Q同学会给出个 ...

随机推荐

  1. lucene-SpanNotQuery和SpanOrQuery交迭与全局跨度

    1.在匹配结果中排除相互交迭的跨度 SpanNotQuery构造函数的第一个参数表示要包含的跨度对象,第二个参数表示要排除的跨度对象. 1) SpanNearQuery quick_fox=new S ...

  2. mplayer最全的命令

    前段时间做过qt内嵌mplayer的一个小程序,感觉mplayer还行不过不支持打开图片感觉有点无力.话不多说上代码: QString path="d:/1.mkv"; QWidg ...

  3. CentOS下将自编译的Apache添加为系统服务

    首先,先谈下对linux服务的理解 1,linux 服务运行方式: 脚本的方式运行,服务脚本存放位置/etc/rc.d/init.d/ 2,linux服务管理软件 chkconfig Red Hat公 ...

  4. PAT (Advanced Level) 1100. Mars Numbers (20)

    简单题. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #in ...

  5. g1gc

    http://www.infoq.com/articles/G1-One-Garbage-Collector-To-Rule-Them-All http://blog.csdn.net/renfufe ...

  6. Java中关于HashMap的使用和遍历(转)

    Java中关于HashMap的使用和遍历 分类: 算法与数据结构2011-10-19 10:53 5345人阅读 评论(0) 收藏 举报 hashmapjavastringobjectiterator ...

  7. IE6 7 父级元素的overflow:hidden 是包不住子级的relative

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  8. PAT (Advanced Level) 1061. Dating (20)

    简单模拟. #include<stdio.h> #include<string.h> ],s2[],s3[],s4[]; ][]={"MON ", &quo ...

  9. POJ 3905 Perfect Election

    2-SAT 裸题,搞之 #include<cstdio> #include<cstring> #include<cmath> #include<stack&g ...

  10. 跨域访问解决方案:JSONP

    关于什么是跨域请求,可以参见我之前的博文:http://www.cnblogs.com/LiuChunfu/p/5240145.html 上述博文最后有提到解决方案,一直说补充,但是工作忙忘了,直到朋 ...