BZOJ 3932 [CQOI2015]任务查询系统 - 差分 + 主席树
Solution
差分就好了, 在$s_i$ 的点+1, $e_i + 1$ 的点 - 1。
查询的时候注意$l == r$ 要返回 $k * b[l]$ ,而不是$sum[node] $因为当前位置的个数可能大于$k$
最后再心疼自己因为神奇建树挂死2333, 被大佬喷了(
Code
#include<cstdio>
#include<cstring>
#include<algorithm>
#define rd read()
#define ll long long
using namespace std; const int N = 2e5 + 1e3; int n, m, num;
int b[N], tot, nd_num;
int lson[N * ], rson[N * ], root[N << ], cnt[N * ];
ll lastans = , sum[N * ]; struct node {
int d, pos, x;
}a[N << ]; int read() {
int X = , p = ; char c= getchar();
for( ;c > '' || c < ''; c = getchar()) if( c == '-') p = -;
for(; c >= '' && c <= ''; c = getchar()) X = X * + c - '';
return X * p;
} int cmp(const node &A, const node &B) {
return A.x < B.x;
} int fd(int x) {
return lower_bound(b + , b + + tot, x) - b;
} void change(int last, int &now, int pos, int d, int l, int r) {
now = ++nd_num;
sum[now] = sum[last] + d * b[pos];
cnt[now] = cnt[last] + d;
lson[now] = lson[last];
rson[now] = rson[last];
if(l == r) return;
int mid = (l + r) >> ;
if(pos <= mid)
change(lson[last], lson[now], pos, d, l, mid);
else
change(rson[last], rson[now], pos, d, mid + , r);
} ll query(int now, int k, int l, int r) {
if(cnt[now] < k) return sum[now];
if(l == r)
return b[l] * k;
int mid = (l + r) >> , tmp;
if((tmp = cnt[lson[now]]) >= k)
return query(lson[now], k, l, mid);
else
return sum[lson[now]] + query(rson[now], k - tmp, mid + , r);
} int main()
{
n = rd; m = rd;
for(int i = ; i <= n; ++i) {
int l = rd, r = rd, pos = rd;
a[++num].d = ;
a[num].pos = pos;
a[num].x = l;
a[++num].d = -;
a[num].pos = pos;
a[num].x = r + ;
b[++tot] = pos;
}
sort(b + , b + + tot);
tot = unique(b + , b + + tot) - b - ;
sort(a + , a + + num, cmp);
for(int i = , j = ; i <= m; ++i) {
root[i] = root[i - ];
for(; j <= num && a[j].x == i; ++j) {
change(root[i], root[i], fd(a[j].pos), a[j].d, , tot);
}
}
for(int i = ; i <= m; ++i) {
int x = rd, A = rd, B = rd, C = rd, k;
k = + (A * lastans + B) % C;
lastans = query(root[x], k, , tot);
printf("%lld\n", lastans);
}
}
BZOJ 3932 [CQOI2015]任务查询系统 - 差分 + 主席树的更多相关文章
- 2018.06.30 BZOJ 3932: [CQOI2015]任务查询系统(主席树)
3932: [CQOI2015]任务查询系统 Time Limit: 20 Sec Memory Limit: 512 MB Description 最近实验室正在为其管理的超级计算机编制一套任务管理 ...
- bzoj 3932 [CQOI2015]任务查询系统(主席树)
Description 最近实验室正在为其管理的超级计算机编制一套任务管理系统,而你被安排完成其中的查询部分. 超级计算机中的任务用三元组(Si,Ei,Pi)描述,(Si,Ei,Pi)表示任务从第Si ...
- [BZOJ3932][CQOI2015]任务查询系统(差分+主席树)
题面 分析 对于一个区间修改(s,e,v),我们可以将它差分,这样就变成了单点修改s和e+1(s插入,t+1删除) 我们用主席树维护差分数组的前缀和,第i棵主席树维护区间[1,i]之间的所有差分值 那 ...
- BZOJ_3932_[CQOI2015]任务查询系统_主席树
BZOJ_3932_[CQOI2015]任务查询系统_主席树 题意: 最近实验室正在为其管理的超级计算机编制一套任务管理系统,而你被安排完成其中的查询部分.超级计算机中的 任务用三元组(Si,Ei,P ...
- bzoj 3932: [CQOI2015]任务查询系统 -- 主席树 / 暴力
3932: [CQOI2015]任务查询系统 Time Limit: 20 Sec Memory Limit: 512 MB Description 最近实验室正在为其管理的超级计算机编制一套任务管 ...
- bzoj3932 / P3168 [CQOI2015]任务查询系统(主席树+差分)
P3168 [CQOI2015]任务查询系统 看到第k小,就是主席树辣 对于每一段任务(a,b,k),在版本a的主席树+k,版本b+1的主席树-k 同一时间可能有多次修改,所以开个vector存操作, ...
- BZOJ3932 CQOI2015 任务查询系统 【主席树】
BZOJ3932 CQOI2015 任务查询系统 Description 最近实验室正在为其管理的超级计算机编制一套任务管理系统,而你被安排完成其中的查询部分.超级计算机中的任务用三元组(Si,Ei, ...
- BZOJ.3932.[CQOI2015]任务查询系统(主席树 差分)
题目链接 对于这一区间的操作,我们可以想到差分+前缀和(感觉也没什么别的了..). 同时对于本题我们能想到主席树,而主席树正是利用前一个节点建树的. 所以离散化.按时间排序,把操作拆成单点加和减即可. ...
- BZOJ 3932: [CQOI2015]任务查询系统 [主席树]
传送门 题意: 任务用三元组(Si,Ei,Pi)描述,(Si,Ei,Pi)表示任务从第Si秒开始,在第Ei秒后结束(第Si秒和Ei秒任务也在运行),其优先级为Pi 调度系统会经常向查询系统询问,第Xi ...
随机推荐
- js正则表达式子校验
//正则表达式校验new RegExp(/^[1-9]\d{4,8}$/,"g").test(1234);//执行一个字符串所表达的方法 eval(this['字符串']) 正则表 ...
- jquery 中attr()的一个用法
html 如下: <ul><li><img src="./img/addface_icon.png" alt="">< ...
- AJAX简单实例
越用AJAX越觉得它的强大.好用. 平常我们提交表单,是直接通过action属性,直接向后台提交数据. 我们也可以用AJAX向后台提交数据.例如: 这是一个表单,两个字段:notice,scort,保 ...
- 在Laravel外独立使用laravel-mongodb
laravel框架外部使用laravel-mongodb 插件 下载安装方式主要根据github上的参考: https://github.com/jenssegers/laravel-mongodb# ...
- java 集合 Se HashTreeSet
Set接口 Set是Collection的子接口,与List相对 Set集合中的元素的特点是1,无序性 2,无下标3,无重复的元素 Set是个接口,所以无法直接创建对象,要依赖它的实现类来创建对象 ...
- unittest测试
标签(空格分隔): unittest unittest介绍: python里面也有单元测试框架-unittest,相当于是一个python版的junit. 一.unittest简介 1.先导入unit ...
- 如何获得scala的帮助和退出
scala> :helpAll commands can be abbreviated, e.g., :he instead of :help.:edit <id>|<line ...
- SQLMAP自动注入(三):参数介绍
--delay延时扫描 --scope 从burpsuit日志中过滤日志内容,通过正则表达式筛选扫描目标,19开头,尾数为1.11.121.221的目标 --level=3 会检查user-agent ...
- Java读取文件-BufferedReader/FileReader/InputStreamReader/FileInputStream的关系和区别
一.Java读取和存储文件数据流 Java读取文件,实际是将文件中的字节流转换成字符流输出到屏幕的过程 这里面涉及到两个类:InputStreamReader和OutputStreamWriter ...
- weechat 常用指令
添加服务器: /server add freenode irc.freenode.org 设置nick: /set irc.server.freenode.nicks "mynick,myn ...