题目描述

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. Spring学习总结(2)——Spring的常用注解

    本文汇总了Spring的常用注解,以方便大家查询和使用,具体如下: 使用注解之前要开启自动扫描功能 其中base-package为需要扫描的包(含子包). ? 1 <context:compon ...

  2. foj 2173 floyd+矩阵快速幂

     Problem 2173 Nostop Accept: 52    Submit: 210 Time Limit: 3000 mSec    Memory Limit : 32768 KB  Pro ...

  3. TortoiseGit生成PuttyKey与GitHub的SSH进行关联

    1.打开Puttygen 要到进度条满格为止,知道出现如下界面: 把上面的Key复制. 最后点击[Save private key]保存. 2.登录GitHub进行如下操作: Settings-> ...

  4. 淘宝内部分享:MySQL & MariaDB性能优化

    发表于2015-01-20 16:26| 28875次阅读| 来源mysql.taobao.org| 22 条评论| 作者淘宝数据库团队 MySQL性能优化淘宝数据库 摘要:MySQL是目前使用最多的 ...

  5. junit4单元测试基础

    导入方法看如下截图就明白了:   新建测试用例 右击包名,点击新建,或者新建里的others,选择JUnit test case,如下图所示:   接下来,给测试类起名字和选择要测试的类,如下图所示: ...

  6. Aizu/Aoj 0121 Seven Puzzle

    这题应该算是经典的八数码问题的弱化版吧:给你一个4x2的方版,上面有0-7 八个数字,每次只能让编号0的方格跟他的上下左右的方格交换:所以也就是把方格0当做空格看待,每次只有空格周围的方格能够向空格处 ...

  7. 【cl】java变量

    知识点一: 变量:有声明,有初始化! 变量作用域:变量在声明的地方开始,到块结束(其中一对{}叫块) 变量不能重复声明(声明=定义):在同一个作用域中不能重复声明变量! 在作用域中如果已经有变量了,就 ...

  8. nyoj--44--子串和(动态规划)

    子串和 时间限制:5000 ms  |  内存限制:65535 KB 难度:3 描述 给定一整型数列{a1,a2...,an},找出连续非空子串{ax,ax+1,...,ay},使得该子序列的和最大, ...

  9. [JavaEE] IBM - Spring 系列: Spring 框架简介

    Spring AOP 和 IOC 容器入门 在这由三部分组成的介绍 Spring 框架的系列文章的第一期中,将开始学习如何用 Spring 技术构建轻量级的.强壮的 J2EE 应用程序.develop ...

  10. HUdson2092整数解

    2019-05-17 16:04:37 加油,坚持就是胜利,fightting m / i的情况,i可能等于0 #include <bits/stdc++.h> using namespa ...