题意:在一个射击游戏里面,游戏者可以选择地面上【1,X】的一个点射击,并且可以在这个点垂直向上射击最近的K个目标,每个目标有一个价值,价值等于它到地面的距离。游戏中有N个目标,每个目标从L覆盖到R,距离地面高度D。每次射击一个目标可以得到目标价值大小的分数,每次射击以后目标不会消失。如果在该点上方的目标个数小于可以射击的次数,那么就当多出来的次数全部射在该点上方最高的目标身上。如果上一个询问 > p,那么本次总得分翻倍。

思路:简单的主席树模板题。区间覆盖直接L上+1,R+1上-1就行了。然后搞一下区间和,区间数量。

代码:

#include<cmath>
#include<set>
#include<map>
#include<queue>
#include<cstdio>
#include<vector>
#include<cstring>
#include <iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int maxn = 1e5 + 10;
const int M = maxn * 30;
const ull seed = 131;
const int INF = 0x3f3f3f3f;
const int MOD = 1e4 + 7;
int n, q, tot;
int root[maxn];
vector<ll> vv;
int getId(int x){
return lower_bound(vv.begin(), vv.end(), x) - vv.begin() + 1;
}
struct node{
int lson, rson;
int num;
ll sum;
}T[maxn * 50];
void update(int l, int r, int &now, int pre, int v, int pos){
T[++tot] = T[pre], T[tot].num += v, T[tot].sum += v * vv[pos - 1], now = tot;
if(l == r) return;
int m = (l + r) >> 1;
if(m >= pos)
update(l, m, T[now].lson, T[pre].lson, v, pos);
else
update(m + 1, r, T[now].rson, T[pre].rson, v, pos);
}
ll query(int l, int r, int now, int k){
if(l == r){
return vv[l - 1] * k;
}
int m = (l + r) >> 1;
int num = T[T[now].lson].num;
ll sum = T[T[now].lson].sum;
if(num >= k)
return query(l, m, T[now].lson, k);
else
return sum + query(m + 1, r, T[now].rson, k - num);
}
ll query_max(int l, int r, int now){
if(l == r) return vv[l - 1];
int m = (l + r) >> 1;
int num = T[T[now].rson].num;
if(num > 0)
return query_max(1, vv.size(), T[now].rson);
else
return query_max(1, vv.size(), T[now].lson);
}
vector<int> g[maxn];
int m, x;
int main(){
ll p;
while(~scanf("%d%d%d%lld", &n, &m, &x, &p)){
tot = 0;
vv.clear();
for(int i = 1; i <= x; i++) g[i].clear();
for(int i = 1; i <= n; i++){
int u, v;
ll d;
scanf("%d%d%lld", &u, &v, &d);
g[u].push_back(d);
if(v + 1 <= x) g[v + 1].push_back(-d);
vv.push_back(d);
}
sort(vv.begin(), vv.end());
vv.erase(unique(vv.begin(), vv.end()), vv.end()); for(int i = 1; i <= x; i++){
root[i] = root[i - 1];
for(int j = 0; j < g[i].size(); j++){
ll v = g[i][j];
update(1, vv.size(), root[i], root[i], v < 0? -1 : 1, getId(abs(v)));
}
} ll pre = 1, ans;
while(m--){
ll xx, a, b, c, k;
scanf("%lld%lld%lld%lld", &xx, &a, &b, &c);
k = (a * pre + b) % c;
if(k > T[root[xx]].num){
ans = T[root[xx]].sum + query_max(1, vv.size(), root[xx]) * (k - T[root[xx]].num);
}
else{
ans = query(1, vv.size(), root[xx], k);
}
if(pre > p) ans *= 2;
printf("%lld\n", ans);
pre = ans;
}
}
return 0;
}

HDU 4866 Shooting(主席树)题解的更多相关文章

  1. HDU 4866 Shooting 题解:主席树

    这题的主要的坑点就是他给你的射击目标有重合的部分,如果你向这些重合的部分射击的话要考虑两种情况: 射击目标数量 ≥ 重合数量 : 全加上 射击目标数量 ≤ 重合数量 : 只加距离*射击目标数量 然而这 ...

  2. HDU 4866 Shooting (主席树)

    题目链接  HDU 4866 题意  给定$n$条线段.每条线段平行$x$轴,离x轴的距离为$D$,覆盖的坐标范围为$[L, R]$.   现在有$m$次射击行动,每一次的射击行动可以描述为在横坐标$ ...

  3. HDU 4866 Shooting 扫描线 + 主席树

    题意: 在二维平面的第一象限有\(n(1 \leq n \leq 10^5)\)条平行于\(x\)轴的线段,接下来有\(m\)次射击\(x \, a \, b \, c\). 每次射击会获得一定的分数 ...

  4. Sequence II HDU - 5919(主席树)

    Mr. Frog has an integer sequence of length n, which can be denoted as a1,a2,⋯,ana1,a2,⋯,anThere are ...

  5. To the moon HDU - 4348 (主席树,区间修改)

    Background To The Moon is a independent game released in November 2011, it is a role-playing adventu ...

  6. Super Mario HDU - 4417 (主席树)

    Mario is world-famous plumber. His “burly” figure and amazing jumping ability reminded in our memory ...

  7. HDU 4348(主席树 标记永久化)

    题面一看就是裸的数据结构题,而且一看就知道是主席树... 一共四种操作:1:把区间[l, r]的数都加上d,并且更新时间.2:查询当前时间的区间和.3:查询历史时间的区间和.4:时光倒流到某个时间. ...

  8. HDU 3727 Jewel 主席树

    题意: 一开始有一个空序列,然后有下面四种操作: Insert x在序列尾部加入一个值为\(x\)的元素,而且保证序列中每个元素都互不相同. Query_1 s t k查询区间\([s,t]\)中第\ ...

  9. K-th occurrence HDU - 6704 (SA, 主席树)

    大意: 给定串$s$, $q$个询问$(l,r,k)$, 求子串$s[l,r]$的第$k$次出现位置. 本来是个简单签到题, 可惜比赛的时候还没学$SA$...... 好亏啊 相同的子串在$SA$中是 ...

随机推荐

  1. OLED的波形曲线、进度条、图片显示(STM32 HAL库 模拟SPI通信 5线OLED屏幕)详细篇

    少废话,先上效果图 屏幕显示效果         全家福 一.基础认识及引脚介绍 屏幕参数: 尺寸:0.96英寸 分辨率:128*64 驱动芯片:SSD1306 驱动接口协议:SPI 引脚说明: 二. ...

  2. uni-app开发经验分享十三:实现手机扫描二维码并跳转全过程

    最近使用 uni-app 开发 app ,需要实现一个调起手机摄像头扫描二维码功能,官网API文档给出了这样一个demo: // 允许从相机和相册扫码 uni.scanCode({ success: ...

  3. 改变JavaScript中函数的内部this指向!

    改变JavaScript中函数的内部this指向! 第一种方法 call call 可以 调用函数 + 改变函数内的this指向! var obj = { name: 'lvhang' } funct ...

  4. Mybatis参数预编译

    Mybatis参数预编译 一.数据库预编译介绍 1.数据库SQL语句编译特性: 数据库接受到sql语句之后,需要词法和语义解析,优化sql语句,制定执行计划.这需要花费一些时间.但是很多情况,我们的一 ...

  5. (014)每日SQL学习:oracle下lag和lead分析函数

    /*语法*/ lag(exp_str,offset,defval) over() Lead(exp_str,offset,defval) over() --exp_str要取的列 --offset取偏 ...

  6. loj10171

    牧场的安排 内存限制:512 MiB 时间限制:1000 ms 原题来自:USACO 2006 Nov. Gold Farmer John 新买了一块长方形的牧场,这块牧场被划分成 MMM 行 NNN ...

  7. easy-ui的datagrid

    <div id="magazineGrid"></div> <script> $('#magazineGrid').datagrid({ hei ...

  8. 3.centos 7执行service iptables save报错问题

    1.报错 [root@localhost ~]# service iptables save The service command supports only basic LSB actions ( ...

  9. Pytest(12)pytest缓存

    前言 pytest 运行完用例之后会生成一个 .pytest_cache 的缓存文件夹,用于记录用例的ids和上一次失败的用例. 方便我们在运行用例的时候加上--lf 和 --ff 参数,快速运行上一 ...

  10. 统计单词出现次数的mapreduce

    1.新建Java项目 2.导包E:\工具\大数据\大数据提升资料\01-软件资料\06-Hadoop\安装包\Java1.8环境下编译\hadoop-2.7.3\hadoop-2.7.3\share\ ...