4056 hdu4866 Shooting
题目描述
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 input consists several test cases.
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 [L, R] and the distance from the starting line is D.
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.
输出
Output M lines each corresponds to one integer.
样例输入
4 3 5 8
1 2 6
2 3 3
2 4 7
1 5 2
2 2 1 5
3 1 1 10
4 2 3 7
样例输出
11
10
18
呼呼呼临走前终于弄出来了,又一道主席树
总之就是维护X棵线段树的感觉,每条线段拆成添加和修改两个操作
如果同一个位置有多个操作的话rt数组就记录做完最后那一次的
不过这题还有别的做法
用两颗主席树去做,一颗负责在加入时加入,一颗负责在删除时加入
这样的话利用可减性,用第一颗减去第二颗就是实际的树了
我比较懒啊,写的第一种算法,不过总感觉有点鬼。。。
为什么跟我的同学比我校平台上我比较快,而hdu上我就被卡成TLE他就A了???
இ௰இ
#include<cstdio>
#include<algorithm>
#define ll long long
using namespace std;
int N,M,X,P,tot,siz,st;
int rt[];
struct node{
int l,r,s;
ll sum;
}t[];
struct mmove{
int x,opt;
ll sum;
}g[];
bool cmp(mmove A,mmove B){return A.x<B.x;}
ll ds[],pre;
int insert(int k,int x,int o,int l,int r){
t[++tot]=t[k];k=tot;
if(l==r){
t[k].s+=o;
t[k].sum+=ds[l]*o;
return k;
}
int mid=(l+r)/;
if(x<=mid) t[k].l=insert(t[k].l,x,o,l,mid);
else t[k].r=insert(t[k].r,x,o,mid+,r);
t[k].s=t[t[k].l].s+t[t[k].r].s;
t[k].sum=t[t[k].l].sum+t[t[k].r].sum;
return k;
}
ll query(int k,int x,int l,int r){
if(l==r)return (t[k].s==?:(t[k].sum/t[k].s)*min(t[k].s,x));
int mid=(l+r)/;
if(t[t[k].l].s>=x)return query(t[k].l,x,l,mid);
else return t[t[k].l].sum+query(t[k].r,x-t[t[k].l].s,mid+,r);
}
int main(){
while(scanf("%d%d%d%d",&N,&M,&X,&P)!=EOF){
pre=;tot=;
t[]=(node){,,,};
for(int i=;i<=N;i++){
scanf("%d%d%lld",&g[i].x,&g[i+N].x,&ds[i]);
g[i+N].x++;
g[i].opt=;g[i+N].opt=-;
g[i+N].sum=g[i].sum=ds[i];
}
sort(ds+,ds++N);
siz=unique(ds+,ds++N)-ds-;
for(int i=;i<=*N;i++)
g[i].sum=lower_bound(ds+,ds++siz,g[i].sum)-ds;
sort(g+,g+*N+,cmp);
st=;
for(int i=;i<=X;i++){
rt[i]=rt[i-];
while(st<=*N&&g[st].x==i){
rt[i]=insert(rt[i],g[st].sum,g[st].opt,,N);
st++;
}
}
for(int i=,x,a,b,c,K;i<=M;i++){
scanf("%d%d%d%d",&x,&a,&b,&c);
K=(1ll*a*pre+b)%c;
pre=query(rt[x],K,,N)*(pre>P?:);
printf("%lld\n",pre);
}
}
}
4056 hdu4866 Shooting的更多相关文章
- HDU4866 Shooting (要持久段树)
意甲冠军: 给你一些并行x行轴.总是询问坐标x的顶部之前,k一个段高度,.标题是必须在线. 思路: 首先要会可持久化线段树(又称主席树和函数式线段树).不会的能够去做下POJ 2104. 把全部线段高 ...
- Shooting Algorithm
Shooting算法是Wenjiang提出的一种优化Lasso(L1 Regularization)和Bridge Regression的算法, 本文以Lasso为例. 对于线性回归问题$\mathb ...
- Linux 常见的trouble shooting故障排错
Linux 常见的trouble shooting故障排错 备份开机所必须运行的程序对一个运维人员来说是非常有必要的.在实际生产环境中,系统和数据基本都是安装在不同的硬盘上面,因为企业最关心的还是数据 ...
- FZU 2144 Shooting Game
Shooting Game Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submi ...
- poj 1719 Shooting Contest
http://poj.org/problem?id=1719 Shooting Contest Time Limit: 1000MS Memory Limit: 10000K Total Subm ...
- 【HDOJ】4056 Draw a Mess
这题用线段树就MLE.思路是逆向思维,然后每染色一段就利用并查集将该段移除,均摊复杂度为O(n*m). /* 4056 */ #include <iostream> #include &l ...
- OD: Heap Exploit : DWORD Shooting & Opcode Injecting
堆块分配时的任意地址写入攻击原理 堆管理系统的三类操作:分配.释放.合并,归根到底都是对堆块链表的修改.如果能伪造链表结点的指针,那么在链表装卸的过程中就有可能获得读写内存的机会.堆溢出利用的精髓就是 ...
- Problem 2144 Shooting Game fzu
Problem 2144 Shooting Game Accept: 99 Submit: 465Time Limit: 1000 mSec Memory Limit : 32768 KB ...
- Shooting Contest 射击比赛 [POJ1719] [CEOI1997] [一题多解]
Description(下有中文题意) Welcome to the Annual Byteland Shooting Contest. Each competitor will shoot to a ...
随机推荐
- 【codeforces 798C】Mike and gcd problem
[题目链接]:http://codeforces.com/contest/798/problem/C [题意] 给你n个数字; 要求你进行若干次操作; 每次操作对第i和第i+1个位置的数字进行; 将 ...
- 洛谷 P1197 BZOJ 1015 [JSOI2008]星球大战 (ZOJ 3261 Connections in Galaxy War)
这两道题长得差不多,都有分裂集合的操作,都是先将所有操作离线,然后从最后一步开始倒着模拟,这样一来,分裂就变成合并,也就是从打击以后最终的零散状态,一步步合并,回到最开始所有星球都被连为一个整体的状态 ...
- JAVA集合泛型,类型擦除,类型通配符上限之类的知识点
感觉定义要比PYTHON严谨很多,一切源于静态语言的特点吧.. 于是语法上就复杂很多,值不值得呢? 参考测试URL: http://www.cnblogs.com/lwbqqyumidi/p/3837 ...
- C#版winform实现UrlEncode
在Asp.net中可以使用Server.HTMLEncode和Server.URLEncode 将文本或URL的特殊字符编码,但在控制台或Winform程序中没有办法使用到这些方法, 解决办法:右击项 ...
- 公告:CSDN博客积分系统升级(暂行版)
各位亲爱的用户: CSDN博客频道将于2014年10月22日23点至10月23日8点进行积分系统的升级,升级期间会影响大家的正常訪问和操作.给大家带来不便.敬请广大用户谅解.很多其它详情见>&g ...
- 我想要得那块牌—记烟台大学第一届"ACM讲堂"
2014年5月23日.烟台大学ACM实验室举办了第一届"ACM讲堂",演讲的主题是"我想要得那块牌",大二和大三的參赛队员以及三位指导老师都进行了演讲. 晚上七 ...
- dwr异常处理
配置异常转换器: dwr.xml: <!-- 异常转换 --> <convert match="java.lang.Exception" converter=&q ...
- 项目产品化——Excel数据库模板化导入(java)
Excel导入可能是代码开发中比較常见的功能,一个项目假设有多个地方须要excel导入数据库.那么开发的工作量也将比較大,项目产品化过程中,将这么一个类似的功能进行封装合并也是必要的.封装好的代码仅仅 ...
- android app 架构设计01
1:本文有摘抄, 1 2 3 4 5 - 开发过程中.需求.设计.编码的一致性 - 整个程序具有统一的风格,比方对话框样式,button风格,色调等UI元素 - 整个程序详细统一的结构,比方不同模块訪 ...
- c27---typedef
// // main.c // typedef #include <stdio.h> /* typedef可以给一个已知的数据类型起别名. typedef 原有的数据类型 别名; 注意: ...