题目描述

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的更多相关文章

  1. HDU4866 Shooting (要持久段树)

    意甲冠军: 给你一些并行x行轴.总是询问坐标x的顶部之前,k一个段高度,.标题是必须在线. 思路: 首先要会可持久化线段树(又称主席树和函数式线段树).不会的能够去做下POJ 2104. 把全部线段高 ...

  2. Shooting Algorithm

    Shooting算法是Wenjiang提出的一种优化Lasso(L1 Regularization)和Bridge Regression的算法, 本文以Lasso为例. 对于线性回归问题$\mathb ...

  3. Linux 常见的trouble shooting故障排错

    Linux 常见的trouble shooting故障排错 备份开机所必须运行的程序对一个运维人员来说是非常有必要的.在实际生产环境中,系统和数据基本都是安装在不同的硬盘上面,因为企业最关心的还是数据 ...

  4. FZU 2144 Shooting Game

    Shooting Game Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submi ...

  5. poj 1719 Shooting Contest

    http://poj.org/problem?id=1719 Shooting Contest Time Limit: 1000MS   Memory Limit: 10000K Total Subm ...

  6. 【HDOJ】4056 Draw a Mess

    这题用线段树就MLE.思路是逆向思维,然后每染色一段就利用并查集将该段移除,均摊复杂度为O(n*m). /* 4056 */ #include <iostream> #include &l ...

  7. OD: Heap Exploit : DWORD Shooting & Opcode Injecting

    堆块分配时的任意地址写入攻击原理 堆管理系统的三类操作:分配.释放.合并,归根到底都是对堆块链表的修改.如果能伪造链表结点的指针,那么在链表装卸的过程中就有可能获得读写内存的机会.堆溢出利用的精髓就是 ...

  8. Problem 2144 Shooting Game fzu

    Problem 2144 Shooting Game Accept: 99    Submit: 465Time Limit: 1000 mSec    Memory Limit : 32768 KB ...

  9. Shooting Contest 射击比赛 [POJ1719] [CEOI1997] [一题多解]

    Description(下有中文题意) Welcome to the Annual Byteland Shooting Contest. Each competitor will shoot to a ...

随机推荐

  1. Django(六)

    一.一大波model操作 1. 创建数据库表 # 单表 # app01_user ==> tb1 # users class User(models.Model): name = models. ...

  2. JavaThread等待/通知经典范式

    JavaThread等待/通知经典范式 package com.stono.thread; import java.text.SimpleDateFormat; import java.util.Da ...

  3. /sys/power/state

    kernel/power/main.c中: /** * state - control system power state. * * show() returns what states are s ...

  4. C++编程-&gt;pair(对组)

    pair 是 一种模版类型.每一个pair 能够存储两个值.这两种值无限制,能够是tuple.vector ,string,struct等等. 首先来看一下pair的函数 初始化.复制等相关操作例如以 ...

  5. python实现高速排序算法(两种不同实现方式)

    # -*- coding: utf-8 -*- """ Created on Fri May 16 17:24:05 2014 @author: lifeix " ...

  6. LeetCode.2-两个数字相加(Add Two Numbers)

    这是悦乐书的第340次更新,第364篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Medium级别的第1题(顺位题号是2).给定两个非空链表,表示两个非负整数. 数字以相反的顺序存储, ...

  7. Hadoop MapReduce编程 API入门系列之挖掘气象数据版本2(十)

    下面,是版本1. Hadoop MapReduce编程 API入门系列之挖掘气象数据版本1(一) 这篇博文,包括了,实际生产开发非常重要的,单元测试和调试代码.这里不多赘述,直接送上代码. MRUni ...

  8. No control record for Activity type 1000/4220/1442 in version 000 / 2017 activity planning/qty planning

    No control record for Activity type 1000/4220/1442 in version 000 / 2017 activity planning/qty plann ...

  9. 创建一个netcore2.0和angular的项目并运行起来

    netcore2.0发布了,喜大普奔. 我们先下载SDK,请看张善友老师的这篇博客 http://www.cnblogs.com/shanyou/p/7363037.html 下载完之后 我用的vs2 ...

  10. 第八课: - 从Microsoft SQL数据库读取

    第 8 课 如何从Microsoft SQL数据库中提取数据 In [1]: # Import libraries import pandas as pd import sys from sqlalc ...