Code:

#include<vector>
#include<cstdio>
#include<algorithm>
#include<string>
#include<iostream>
#include<cstring> using namespace std; void SetIO(string a){
string in = a + ".in";
freopen(in.c_str(), "r", stdin);
} const int maxn = 100000 + 4; struct Task{
int st, ed, val;
Task(int st = 0, int ed = 0, int val = 0):st(st), ed(ed), val(val){}
}task[maxn]; int Sorted[maxn]; int n, m; void Read(){
scanf("%d%d",&m,&n);
for(int i = 1;i <= m; ++i)
{
int a, b, c;
scanf("%d%d%d",&a,&b,&c);
task[i] = Task(a, b, c);
Sorted[i] = task[i].val;
}
} struct Type{
int delta, val;
Type(int delta=0, int val=0):delta(delta), val(val){}
};
vector<Type>G[maxn]; void Disperse(){
sort(Sorted + 1, Sorted + 1 + m);
for(int i = 1;i <= m; ++i){ task[i].val = lower_bound(Sorted + 1, Sorted + 1 + m, task[i].val) - Sorted; G[task[i].st].push_back(Type(1, task[i].val));
G[task[i].ed + 1].push_back(Type(-1, task[i].val));
}
} const int Tree_const = 50; int numv[maxn * Tree_const], root[maxn]; long long sumv[maxn * Tree_const]; struct Chair_Tree{ int lson[maxn * Tree_const], rson[maxn * Tree_const], cnt_Tree; void build(int l, int r, int &o){
if(l > r) return ; o = ++cnt_Tree; if(l == r) return ; int mid = (l + r) >> 1; build(l, mid, lson[o]);
build(mid + 1, r, rson[o]);
} int insert(int l, int r, int o, int pos, int delta){
int oo = ++cnt_Tree;
lson[oo] = lson[o];
rson[oo] = rson[o];
numv[oo] = numv[o] + delta;
sumv[oo] = sumv[o] + delta * Sorted[pos];
int mid = (l + r) >> 1; if(l == r) return oo; if(pos <= mid)
lson[oo] = insert(l, mid, lson[o], pos, delta);
else
rson[oo] = insert(mid + 1, r, rson[o], pos, delta); return oo;
} long long query(int l, int r, int cur, int k){
if(l == r) return k * Sorted[l]; int lnum = numv[lson[cur]] ;
int mid = (l + r) >> 1; if(k <= lnum)
return query(l, mid,lson[cur], k);
else
return sumv[lson[cur]] + query(mid + 1, r, rson[cur], k - lnum);
} }Tree; void Build(){ Tree.build(1, m, root[0]); for(int i = 1;i <= n; ++i){
int siz = G[i].size();
int rt = root[i - 1]; for(int j = 0;j < siz; ++j){
rt = Tree.insert(1, m, rt, G[i][j].val, G[i][j].delta);
}
root[i] = rt;
} } void Init(){
Read();
Disperse();
Build();
} void Work(){
long long pre = 1;
for(int i = 1;i <= n; ++i){
int x, k, a, b, c;
scanf("%d%d%d%d",&x,&a,&b,&c);
k = 1 + (a * pre + b) % c; if(numv[root[x]] < k)
pre = sumv[root[x]] ;
else
pre = Tree.query(1, m, root[x], k);
printf("%lld\n", pre);
}
} int main(){
SetIO("input");
Init();
Work();
return 0;
}

  

[CQOI2015]任务查询系统 主席树_差分的更多相关文章

  1. 洛谷P3168 [CQOI2015]任务查询系统 [主席树,差分]

    题目传送门 任务查询系统 题目描述 最近实验室正在为其管理的超级计算机编制一套任务管理系统,而你被安排完成其中的查询部分.超级计算机中的任务用三元组(Si,Ei,Pi)描述,(Si,Ei,Pi)表示任 ...

  2. BZOJ3932: [CQOI2015]任务查询系统 主席树

    3932: [CQOI2015]任务查询系统 Time Limit: 20 Sec  Memory Limit: 512 MBSubmit: 4869  Solved: 1652[Submit][St ...

  3. [CQOI2015]任务查询系统 主席树

    [CQOI2015]任务查询系统 LG传送门 以前还没见过主席树的这种写法. 考虑使用差分的思想处理每一个任务,然后所有的东西就都能顺理成章地用主席树维护了,查询的时候和平时的主席树有一点不同,详见代 ...

  4. bzoj 3932: [CQOI2015]任务查询系统 -- 主席树 / 暴力

    3932: [CQOI2015]任务查询系统 Time Limit: 20 Sec  Memory Limit: 512 MB Description 最近实验室正在为其管理的超级计算机编制一套任务管 ...

  5. 【BZOJ3932】[CQOI2015]任务查询系统 主席树

    [BZOJ3932][CQOI2015]任务查询系统 Description 最近实验室正在为其管理的超级计算机编制一套任务管理系统,而你被安排完成其中的查询部分.超级计算机中的 任务用三元组(Si, ...

  6. BZOJ.3932.[CQOI2015]任务查询系统(主席树 差分)

    题目链接 对于这一区间的操作,我们可以想到差分+前缀和(感觉也没什么别的了..). 同时对于本题我们能想到主席树,而主席树正是利用前一个节点建树的. 所以离散化.按时间排序,把操作拆成单点加和减即可. ...

  7. BZOJ 3932: [CQOI2015]任务查询系统 [主席树]

    传送门 题意: 任务用三元组(Si,Ei,Pi)描述,(Si,Ei,Pi)表示任务从第Si秒开始,在第Ei秒后结束(第Si秒和Ei秒任务也在运行),其优先级为Pi 调度系统会经常向查询系统询问,第Xi ...

  8. BZOJ3932[CQOI2015]任务查询系统——主席树

    题目描述 最近实验室正在为其管理的超级计算机编制一套任务管理系统,而你被安排完成其中的查询部分.超级计算机中的 任务用三元组(Si,Ei,Pi)描述,(Si,Ei,Pi)表示任务从第Si秒开始,在第E ...

  9. BZOJ 3932: [CQOI2015]任务查询系统 (主席树板题)

    就是裸的主席树,差分之后排序插入主席树就行了. 注意主席树查询的时候叶子节点要特判,因为本身是有size的 还有要开longlong CODE #include <cctype> #inc ...

随机推荐

  1. Windos下的6种IO模型简要介绍

    windows进行数据的收发有6种IO模型.分别是阻塞(blocking)模型,选择(select)模型,异步选择(WSAAsyncSelect)模型,事件选择(WSAEventSelect )模型, ...

  2. JAVA 静态内部类--转自http://bbs.csdn.net/topics/350021609

    内部类其实并不是非要声明成static的..主要还是要看实际情况决定..静态和非静态有不同的作用.. 引用一篇文章给楼主参考下吧. 在一个类中创建另外一个类,叫做成员内部类.这个成员内部类可以静态的( ...

  3. 新物理AI将可能成为量子计算革命的关键

    新物理AI将可能成为量子计算革命的关键 据外媒报道,量子计算无疑是现在最令人兴奋的技术之一,但它的量子物理基础却让它成为了一个令人讨厌的概念理解甚至很难再展开其他事情.然而,最近物理学研究的一项突破可 ...

  4. BZOJ 3510 首都 (LCT)

    洛谷P4299传送门 题目大意:给你一颗树,边是一条一条连上去的 在连接过程中会存在询问,询问当前节点所在联通块(其实是一颗树)的重心是哪个节点 以及森林中所有树的重心的异或和 在做这道题之前,要先了 ...

  5. Qt编程—去掉标题栏和设置窗口透明用法

    学习Qt编程,有时候我们很想做出好看又比较炫的画面,这时就常用到qt上的一些技巧. 这里我以一个小例子来展示qt的这些技巧,此qt编程写的,如图:(去掉标题栏和设置窗口透明后) 代码实现部分: .h文 ...

  6. 紫书 例题8-1 UVa 120(构造法)

    #include<cstdio> #include<iostream> #include<sstream> #include<algorithm> #d ...

  7. IDEA Maven Web项目 clone到本地导入到Eclipse中,启动服务器的时候会出现这个错误:SEVERE: Exception starting filter [hiddenHttpMethodFilter]

    背景(Background): 我将一个IDEA的maven web项目clone到本地,并导入到Eclipse中. I imported a MAVEN WEB project which was ...

  8. js手动定时清除localStorage

    <script type="text/javascript"> // 假设要保存变量 a 的值,过期时间为 3600秒 // 保存值 var obj = new Obj ...

  9. php获取时间是星期几

    PHP星期几获取代码: date("l"); //data就可以获取英文的星期比如Sundaydate("w"); //这个可以获取数字星期比如123,注意0是 ...

  10. 【Codeforces Round #482 (Div. 2) C】Kuro and Walking Route

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 把x..y这条路径上的点标记一下. 然后从x开始dfs,要求不能走到那些标记过的点上.记录节点个数为cnt1(包括x) 然后从y开始 ...