HDU 4866Shooting
来源:互联网 发布:叙利亚内战 知乎 编辑:程序博客网 时间:2024/06/07 01:27
In the shooting game, the player can choose to stand in the position of 1,X to shoot, you can shoot all the nearest K targets. The value of K may be different on different shootings. There are N targets to shoot, each target occupy the position of Li,Ri , the distance from the starting line is Di(1<=i<=N). Shooting a target can get the bonus points equal to the distance to the starting line. After each shooting targets still exist. Additional, if the previous bonus points is more than P, then as a reward for the shooting present bonus points doubled(and then check the next one). Player wants to know the bonus points he got in each shot.
The first line has two integers, N, M, X, P(1<=N, M ,X<=100000, P<=1000000000), N represents the total number of target shooting, M represents the number of shooting.
The next N lines of three integers L, R, D (1<=L<=R<=X, 1<=D<=10000000), occupy the position of
The next M lines, each line contains four integers x, a, b, c (1<=x<=X, 0<=a,b<=N, 1<=c<=10000000), and K = ( a * Pre + b ) % c. Pre is the bonus point of previous shooting , and for the first shooting Pre=1. It denotes standing in the position x and the player can shoot the nearest K targets.
4 3 5 81 2 62 3 32 4 71 5 22 2 1 53 1 1 104 2 3 7
111018
简单地说,题意是给出n条线段,m个询问,在线的求在x位置上,高度小的前k条线段的高度和。
直接把线段拆成左右两个端点,然后用主席树顺着建树,询问的时候直接在对应树上求前k小的和即可。
题目的空间足够,不用离散化也可以。
#include<map>#include<ctime>#include<cmath> #include<queue> #include<string>#include<vector>#include<cstdio> #include<cstring> #include<iostream>#include<algorithm> #include<functional>using namespace std;#define ms(x,y) memset(x,y,sizeof(x)) #define rep(i,j,k) for(int i=j;i<=k;i++) #define per(i,j,k) for(int i=j;i>=k;i--) #define loop(i,j,k) for (int i=j;i!=-1;i=k[i]) #define inone(x) scanf("%d",&x) #define intwo(x,y) scanf("%d%d",&x,&y) #define inthr(x,y,z) scanf("%d%d%d",&x,&y,&z) #define infou(x,y,z,p) scanf("%d%d%d%d",&x,&y,&z,&p) typedef long long LL;const int low(int x) { return x&-x; }const int INF = 0x7FFFFFFF;const int mod = 1e9 + 7;const int N = 2e5 + 10;const int M = 5e6;const double eps = 1e-10;int n, m, len, P, D, x, y, z, a;int ft[N], nt[N], u[N], sz;int rt[N], f[M], L[M], R[M], tot;LL g[M];void insert(int x, int &y, int l, int r, int u){y = ++tot; L[y] = L[x]; R[y] = R[x]; f[y] = f[x] + u / abs(u); g[y] = g[x] + u;if (l == r) return;int mid = l + r >> 1;if (abs(u) <= mid) insert(L[x], L[y], l, mid, u);else insert(R[x], R[y], mid + 1, r, u);}LL get(int x, int l, int r, int k){if (!k || l == r) return 1LL * min(k, f[x]) * l;int mid = l + r >> 1;if (f[L[x]] <= k) return g[L[x]] + get(R[x], mid + 1, r, k - f[L[x]]);return get(L[x], l, mid, k);}int main(){while (~infou(n, m, len, P)){tot = D = sz = 0;rep(i, 1, len) ft[i] = -1;rep(i, 1, n){inthr(x, y, z);u[sz] = z; nt[sz] = ft[x]; ft[x] = sz++;u[sz] = -z; nt[sz] = ft[y + 1]; ft[y + 1] = sz++;D = max(D, z);}rep(i, 1, len){int k = rt[i - 1];loop(j, ft[i], nt) insert(k, rt[i], 1, D, u[j]), k = rt[i];rt[i] = k;}LL pre = 1;rep(i, 1, m){infou(a, x, y, z);pre = (pre > P ? 2 : 1) * get(rt[a], 1, D, (1LL * x * pre + y) % z);printf("%I64d\n", pre);}}return 0;}
0 0
- hdu 4866 Shooting
- HDU 4866Shooting
- 【HDU】4866 Shooting 主席树
- hdu 4866 Shooting(主席树)
- HDU 4866(Shooting-主席树)
- HDU-4866-Shooting(函数式线段树)
- HDU 4866 Shooting 扫描线+主席树
- HDU 4866 Shooting 题解:主席树
- hdu 4866 Shooting(主席树学习第三弹)
- hdu - 4327 - Shooting - 立体几何 + 半平面交
- [HDOJ 4866] Shooting [可持久化线段树]
- Trouble Shooting
- trouble shooting
- Shooting Game
- TYVJ1360Imperishable Shooting
- HDU4866-Shooting
- Shooting an Elephant
- XL Trouble Shooting
- OpenJudge Mooc 5.1 Zipper
- Spring中属性注入的几种方式以及复杂属性的注入
- javaWEB总结(22):session的常用方法
- GB2312、GBK、GB18030 、UTF-8、Unicode、ASCII这几种字符集的主要区别是什么?
- Java远程通讯可选技术及原理
- HDU 4866Shooting
- HPUOJ---2017寒假作业--专题-1/M-人见人爱A^B
- HOLCON源码学习
- Eclipse安装maven插件
- Codeforces Beta Round #5 C. Longest Regular Bracket Sequence 括号序列 dp+栈
- (学习总结)鸟哥基础篇第三版:第二十一章
- opengl常见问题
- Socket心跳包机制
- bzoj 2744: [HEOI2012]朋友圈 网络流