Luogu 3168 [CQOI2015]任务查询系统
区间修改单点查询,又观察到是一个k小,考虑主席树上做差分
一开始样例疯狂挂,后来发现主席树在一个历史版本上只能修改一次,所以要开2*n个根结点,记录一下每个时间对应的根结点编号
然后80分,考虑到当一个排名的结点有w个而查询的k<w时会使答案变大,所以特判(但是一开始又喜闻乐见地把符号写反了)~
一通乱改+疯狂提交后水过
Code:
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll; const int N = 1e5 + ;
const ll inf = (ll) << ; int n, qn, bel[N], maxn = ;
ll val[N];
vector <int> ins[N], del[N]; struct Task {
int st, ed;
ll pri;
} a[N]; struct Innum {
int id;
ll val;
} in[N]; bool cmp(const Innum &x, const Innum &y) {
if(x.val != y.val) return x.val < y.val;
else return x.id < y.id;
} template <typename T>
inline void read(T &X) {
X = ;
char ch = ;
T op = ;
for(; ch > ''|| ch < ''; ch = getchar())
if(ch == '-') op = -;
for(; ch >= '' && ch <= ''; ch = getchar())
X = (X << ) + (X << ) + ch - ;
X *= op;
} inline int max(int x, int y) {
return x > y ? x : y;
} inline void discrete() {
in[].val = -inf;
sort(in + , in + + n, cmp);
int cnt = ;
for(int i = ; i <= n; i++) {
if(in[i].val != in[i - ].val) ++cnt;
maxn = max(maxn, cnt);
val[cnt] = in[i].val;
a[in[i].id].pri = cnt;
}
} struct Node {
int lc, rc, cntSum;
ll priSum;
}; namespace PSegT {
int root[N << ], nodeCnt;
Node s[N * ]; #define mid (l + r) / 2 inline void up(int p) {
s[p].cntSum = s[s[p].lc].cntSum + s[s[p].rc].cntSum;
s[p].priSum = s[s[p].lc].priSum + s[s[p].rc].priSum;
} void insert(int &p, int l, int r, int x, int pre, int type) {
p = ++nodeCnt;
s[p] = s[pre];
s[p].cntSum += type;
s[p].priSum += (ll)type * val[x]; if(l == r) return; if(x <= mid) insert(s[p].lc, l, mid, x, s[pre].lc, type);
else insert(s[p].rc, mid + , r, x, s[pre].rc, type); // up(p);
} ll query(int p, int l, int r, int k) {
// if(l == r) return s[p].priSum;
if(l == r) return k < s[p].cntSum ? (ll)k * val[l] : s[p].priSum;
int now = s[s[p].lc].cntSum; ll res = ;
if(k <= now) res = query(s[p].lc, l, mid, k);
else res = s[s[p].lc].priSum + query(s[p].rc, mid + , r, k - now);
return res;
} void print(int p, int l, int r) {
printf("(%d %d %d %d %lld) ", p, s[p].lc, s[p].rc, s[p].cntSum, s[p].priSum);
if(l == r) return;
print(s[p].lc, l, mid);
print(s[p].rc, mid + , r);
} #undef mid } using namespace PSegT; int main() {
read(n), read(qn);
for(int i = ; i <= n; i++) {
read(a[i].st), read(a[i].ed), read(a[i].pri);
in[i].val = a[i].pri, in[i].id = i;
ins[a[i].st].push_back(i);
del[a[i].ed + ].push_back(i);
}
discrete(); nodeCnt = root[] = ;
int rtCnt = ;
for(int i = ; i <= qn; i++) {
for(unsigned int j = ; j < ins[i].size(); j++)
++rtCnt, insert(root[rtCnt], , maxn, a[ins[i][j]].pri, root[rtCnt - ], );
for(unsigned int j = ; j < del[i].size(); j++)
++rtCnt, insert(root[rtCnt], , maxn, a[del[i][j]].pri, root[rtCnt - ], -);
bel[i] = rtCnt;
} /* for(int i = 1; i <= rtCnt; i++, printf("\n"))
print(root[i], 1, maxn); */ ll ans = ;
for(int x, k, _a, _b, _c; qn--; ) {
read(x), read(_a), read(_b), read(_c);
k = + ((ll)_a * ans + _b) % _c;
if(k >= s[root[bel[x]]].cntSum) printf("%lld\n", ans = s[root[bel[x]]].priSum);
else printf("%lld\n", ans = query(root[bel[x]], , maxn, k));
} return ;
}
感觉vector还挺快的……
Luogu 3168 [CQOI2015]任务查询系统的更多相关文章
- Luogu P3168 [CQOI2015]任务查询系统
题目链接 \(Click\) \(Here\) 差分主席树,就是把主席树做成一个差分前缀和的形式,还是很容易想到的. 写主席树的时候几个注意点: 查询可能开始于所有任务之前,二分任务点要把左边界设置为 ...
- 「Luogu P3168 [CQOI2015]任务查询系统」
介绍本题的两种做法: 方法1 前置芝士 线段树:一个很重要的数据结构. 树状数组:一个很重要的数据结构. 具体实现 区间修改,单点查询很容易就会想到树状数组了,至于查询前k个数的和又可以丢给权值线段树 ...
- 主席树||可持久化线段树||离散化||[CQOI2015]任务查询系统||BZOJ 3932||Luogu P3168
题目: [CQOI2015]任务查询系统 题解: 是一道很经典的题目.大体思路是抓优先级来当下标做主席树,用时刻作为主席树的版本.然而优先级范围到1e7去了,就离散化一遍.然后把每个事件的开始(s). ...
- BZOJ_3932_[CQOI2015]任务查询系统_主席树
BZOJ_3932_[CQOI2015]任务查询系统_主席树 题意: 最近实验室正在为其管理的超级计算机编制一套任务管理系统,而你被安排完成其中的查询部分.超级计算机中的 任务用三元组(Si,Ei,P ...
- BZOJ3932: [CQOI2015]任务查询系统 主席树
3932: [CQOI2015]任务查询系统 Time Limit: 20 Sec Memory Limit: 512 MBSubmit: 4869 Solved: 1652[Submit][St ...
- P3168 [CQOI2015]任务查询系统
题目地址:P3168 [CQOI2015]任务查询系统 主席树的模板题 更模板的在这儿:P3834 [模板]可持久化线段树 1(主席树) 形象的说,P3834是"单点修改,区间查询" ...
- bzoj3932 / P3168 [CQOI2015]任务查询系统(主席树+差分)
P3168 [CQOI2015]任务查询系统 看到第k小,就是主席树辣 对于每一段任务(a,b,k),在版本a的主席树+k,版本b+1的主席树-k 同一时间可能有多次修改,所以开个vector存操作, ...
- 2018.06.30 BZOJ 3932: [CQOI2015]任务查询系统(主席树)
3932: [CQOI2015]任务查询系统 Time Limit: 20 Sec Memory Limit: 512 MB Description 最近实验室正在为其管理的超级计算机编制一套任务管理 ...
- [CQOI2015]任务查询系统 主席树
[CQOI2015]任务查询系统 LG传送门 以前还没见过主席树的这种写法. 考虑使用差分的思想处理每一个任务,然后所有的东西就都能顺理成章地用主席树维护了,查询的时候和平时的主席树有一点不同,详见代 ...
随机推荐
- L117
Hoover has become a household word for a vacuum cleaner through the world.Economics are slowly killi ...
- Codeforces Round #266 (Div. 2)B(暴力枚举)
很简单的暴力枚举,却卡了我那么长时间,可见我的基本功不够扎实. 两个数相乘等于一个数6*n,那么我枚举其中一个乘数就行了,而且枚举到sqrt(6*n)就行了,这个是暴力法解题中很常用的性质. 这道题找 ...
- volatile关键字及内存可见性
先看一段代码: package com.java.juc; public class TestVolatile { public static void main(String[] args) { T ...
- LeetCode 251. Flatten 2D Vector
原题链接在这里:https://leetcode.com/problems/flatten-2d-vector/ 题目: Implement an iterator to flatten a 2d v ...
- django1.7 HTML模板中{%url%}的使用
转载:https://my.oschina.net/jastme/blog/345265
- Angular 隨記
Windows下更新Node 和NPM方法 管理員模式打開powershell 執行以下命令: Set-ExecutionPolicy Unrestricted -Scope CurrentUser ...
- Jeesite开垦
1. userIndex里面,$ctx是在哪里定义的? 就是request.context 2. 增加新的包后,扫描配置修改1) spring-context.xml文件中,扫描非@controlle ...
- BZOJ3745:[COCI2015]Norma
浅谈离线分治算法:https://www.cnblogs.com/AKMer/p/10415556.html 题目传送门:https://lydsy.com/JudgeOnline/problem.p ...
- window内置对象学习
1.location:本页面的location对象 对象属性图示: 对象属性: 对象方法: 2.history:是本页面的浏览历史 history对象记录了用户曾经浏览过的页面(URL),并可以实现浏 ...
- 通过Azure File Service搭建基于iscsi的共享盘
在Azure上目前已经有基于Samba协议的共享存储了. 但目前在Azure上,还不能把Disk作为共享盘.而在实际的应用部署中,共享盘是做集群的重要组件之一.比如仲裁盘.Shared Disk等. ...