HDU 4866 Shooting

In the shooting game, the player can choose to stand in the position of  1,X 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 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 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 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
Sample Output
11
10

18

简单地说,题意是给出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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值