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 ...
随机推荐
- java IO(BIO)、NIO、AIO
IO 服务端ServerSocket 客户端Socket 缺点每次客户端建立连接都会另外启一个线程处理.读取和发送数据都是阻塞式的. 如果1000个客户端建立连接将会产生1000个线程 Server端 ...
- floyd求最小环 模板
http://www.cnblogs.com/Yz81128/archive/2012/08/15/2640940.html 求最小环 floyd求最小环 2011-08-14 9:42 1 定义: ...
- 论文WAN Optimized Replication of Backup Datasets Using Stream-Informed Delta Compression
这是EMC的备份小组发表在FAST12上的论文,主要是结合重删和差量数据压缩的方法,达到更高的数据压缩率.并且作者使用了一种基于数据流的差量数据压缩,消除了对索引的需求.通过测试达到的压缩效 ...
- HDU 3662
求的是凸包有多少个面. 注意,求的是面.这就需要把同一个面的三角形合并.只需判断两个三角形的法向量是否同向平行. /* 增量法求凸包.选取一个四面体,同时把它各面的方向向量向外,增加一个点时,若该点与 ...
- [React] Update State Based on Props using the Lifecycle Hook getDerivedStateFromProps in React16.3
getDerivedStateFromProps is lifecycle hook introduced with React 16.3 and intended as a replacement ...
- 简陋版:基于python的自动化测试框架开发
项目背景: XXXX银行项目采用的是B/S架构,主要是为了解决银行业务中的柜员.凭证.现金.账务等来自存款.贷款.会计模块的管理. 手工弊端: 1.项目业务复杂度高,回归测试工作量大2.单个接口功能比 ...
- Unity3D与JSP TomCatserver传递数据和文件( 二 ) Unity3D向java传输表单
扫码关注微信公众号,获取最新资源 经历了一天的工作.我又来更新啦...白天手欠,把上一个给删了.明天重写吧.. 废话不多说.我们先去Unity里创建一个能够输入username和password的登录 ...
- 2016.04.18,英语,《Vocabulary Builder》Unit 15
term/termin, comes from the Latin verb terminare, 'to limit, bound, or set limits to', or the relate ...
- oc16--set,get
// // Kline.h // day13 #import <Foundation/Foundation.h> @interface Kline : NSObject { int _ma ...
- apt-get常见错误
安装错误:“E: Unmet dependencies.” 原因:非正常停止apt-get install * 错误提示:E: Unmet dependencies. Try 'apt-get - ...