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的运算符即可。
#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:分配游戏【树状数组】的更多相关文章
- 【BZOJ4881】5月月赛D 线段游戏 树状数组+set
Description quailty和tangjz正在玩一个关于线段的游戏.在平面上有n条线段,编号依次为1到n.其中第i条线段的两端点坐 标分别为(0,i)和(1,p_i),其中p_1,p_2,. ...
- 【bzoj4881】[Lydsy2017年5月月赛]线段游戏 树状数组+STL-set
题目描述 quailty和tangjz正在玩一个关于线段的游戏.在平面上有n条线段,编号依次为1到n.其中第i条线段的两端点坐标分别为(0,i)和(1,p_i),其中p_1,p_2,...,p_n构成 ...
- HDU 5465 Clarke and puzzle Nim游戏+二维树状数组
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5465 Clarke and puzzle Accepts: 42 Submissions: 26 ...
- 【Tsinsen A1339】JZPLCM (树状数组)
Description 原题链接 给定一长度为\(~n~\)的正整数序列\(~a~\),有\(~q~\)次询问,每次询问一段区间内所有数的\(~LCM~\)(即最小公倍数).由于答案可能很大,输出 ...
- bzoj 4372 烁烁的游戏——动态点分治+树状数组
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=4372 和 bzoj 3070 震波 是一个套路.注意区间修改的话,树状数组不能表示 dis ...
- bzoj 4372 烁烁的游戏 —— 动态点分治+树状数组
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=4372 本以为和 bzoj3730 一样,可以直接双倍经验了: 但要注意一下,树状数组不能查询 ...
- BZOJ 1103: [POI2007]大都市meg [DFS序 树状数组]
1103: [POI2007]大都市meg Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 2221 Solved: 1179[Submit][Sta ...
- 树形DP+DFS序+树状数组 HDOJ 5293 Tree chain problem(树链问题)
题目链接 题意: 有n个点的一棵树.其中树上有m条已知的链,每条链有一个权值.从中选出任意个不相交的链使得链的权值和最大. 思路: 树形DP.设dp[i]表示i的子树下的最优权值和,sum[i]表示不 ...
- 树状数组---Squared Permutation
BNUOJ 51636 最近,无聊的过河船同学在玩一种奇怪的名为“小Q的恶作剧”的纸牌游戏. 现在过河船同学手有张牌,分别写着,打乱顺序之后排成一行,位置从左往右按照标号. 接下来小Q同学会给出个 ...
随机推荐
- SDAU课程练习--problemQ(1016)
题目描述 FJ is surveying his herd to find the most average cow. He wants to know how much milk this 'med ...
- UIRoot
scalingStyle: Flexible:固定大小,不管设备屏幕的大小是多少,都以固定的像素显示UI Constrained: 可适应屏幕 如要使640*480像素的背景图适应屏幕,要如下设置 c ...
- 学习笔记——代理模式Proxy
代理模式,主要是逻辑和实现解耦.具体逻辑如何,由代理Proxy自己来设计,我们只需要把逻辑Subject交给代理即可. 主要应用场景,包括创建大开销对象时,使用代理来慢慢创建:远程代理,如网络不确定时 ...
- IDL 实现求算 DEM 坡度坡向
关于坡度坡向的定义,请Google之. 源码: IDL 源码PRO ASPECT_SLOPE,DEM,ASPECT = ASPECT,SLOPE=SLOPE,PIXELSIZE = PIXELSIZE ...
- Leetcode389
Find the Difference Given two strings s and t which consist of only lowercase letters. 给出两个字符串,s和t,都 ...
- laytpl.js 模板使用记录
{{# for(var j = 0, len = d.length; j < len; j++){ }} <div class="pure-u-1-5 pure-u-sm-1 p ...
- Delphi MaskEdit用法(转)
源:http://www.cnblogs.com/zhangzhifeng/archive/2011/10/12/2208640.html MaskEdit是用来建立编辑框的,但它与Edit编辑框可以 ...
- 2016沈阳网络赛 QSC and Master
QSC and Master Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) ...
- css一些特别效果设定
在CSS中,BOX的Padding属性的数值赋予顺序为 padding:10px; 四个内边距都是10pxpadding:5px 10px; 上下5px 左右10pxpadding:5px 10px ...
- POJ 3683 Priest John's Busiest Day
2-SAT简单题,判断一下两个开区间是否相交 #include<cstdio> #include<cstring> #include<cmath> #include ...