2014多校1(1006)hdu4866

来源:互联网 发布:小米摄像头app软件 编辑:程序博客网 时间:2024/05/21 10:25

Shooting

Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 903    Accepted Submission(s): 180


Problem Description
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.

 

Input
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
Output M lines each corresponds to one integer.
 

Sample Input
4 3 5 81 2 62 3 32 4 71 5 22 2 1 53 1 1 104 2 3 7
 

Sample Output
111018

最开始不知道函数式线段树这东西,一直想用普通线段树搞,真是方法不对劳命伤财啊~

思路:讲所有目标距X轴的距离离散化为函数式线段树的值,然后按区间端点顺序将目标距离插入函数式线段树,左端点+1,右端点-1,分别表示在或不在,注意这里是有多少个区间端点就有多少颗树,每棵树形态大小一样,只是部分节点存的值有差别

树建好之后就是查找了,对于任意一个位置X,可以用二分查找出在X左边离它最近的区间端点,然后在该端点对应的线段树上查找前K个目标的和即可。

这里线段树每个节点只需维护两个值,一个是值的数量,一个是区间总和

0 0
原创粉丝点击