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 ...
随机推荐
- Docker学习总结(16)——当当网Docker应用实践
随着Docker成为当下热门的容器技术,各大公司以及中小团队都开始选择Docker来进行应用部署,从原有部署方式迁移到Docker方式过程中难免会遇到各种问题,本次分享主要介绍当当网个性化推荐组应用D ...
- 程序错误通常有2种,一种是运行时错误,这种错误ide会抛出异常,我们可以根据异常寻找问题.
1.程序错误通常有2种,一种是运行时错误,这种错误ide会抛出异常,我们可以根据异常寻找问题. 2.可以根据异常寻找问题. 3.可以根据异常寻找问题
- ViewPage+Frament+listView滑动效果
近期在做一个须要使用Frament+ViewPage制作一个滑动的效果,看了非常多资料,最终实现了,这与大家分享一下战果 总结一下.这里我做了一个Demo分享给大家 我的文件文件夹结构图 1.首先要有 ...
- 【翻译自mos文章】Oracle GoldenGate 怎么在源头的传输进程和目的端的server/collector进程之间分配 port?
Oracle GoldenGate 怎么在源头的传输进程和目的端的server/collector进程之间分配 port? 来源于: How Does GoldenGate Allocates Por ...
- java中String的21种使用方法
(构造函数必须new出来) * public String (char[] vaue) 将一个字符数组变成字符串(构造函数) * public Stri ...
- A. Music(Codeforces Round #315 (Div. 2) 求最大的容纳量)
A. Music time limit per test 2 seconds memory limit per test 256 megabytes input standard input outp ...
- 深入理解groupByKey、reduceByKey区别——本质就是一个local machine的reduce操作
下面来看看groupByKey和reduceByKey的区别: val conf = new SparkConf().setAppName("GroupAndReduce").se ...
- 如何让音频跟视频在ios跟android上自动播放
如何让音频跟视频在ios跟android上自动播放 <audio autoplay ><source src="audio/alarm1.mp3" type=&q ...
- jupyter在特定环境特定目录中启动
代码如下: @echo off start %windir%\System32\cmd.exe "/c" D:\Anaconda\Scripts\activate.bat # 启动 ...
- 27. Remove Element[E]移除元素
题目 Given an array nums and a value val, remove all instances of that value in-place and return the n ...