任务查询系统(bzoj 3932)
Description
Input
Output
Sample Input
1 2 6
2 3 3
1 3 2
3 3 4
3 1 3 2
1 1 3 4
2 2 4 3
Sample Output
8
11
HINT
/*
做完这道题,感觉自己对主席树的理解还是蒙蔽的
很显然,我们需要对于每个时间点维护一个线段树,修改时运用差分的原理,对于在x~y上修改就在x上+1,在y+1上-1, 这样就完美契合了主席树。
对于每棵线段树,从小到大维护优先级即可。
*/
#include<cstdio>
#include<iostream>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#define N 300010
#define lon long long
using namespace std;
lon n,m,lim,cnt,cn,to[N*],root[N*],son[N*][],w[N*],sum[N*];
struct node{
lon pos,v;
};node e[N*];
lon read(){
lon num=,flag=;char c=getchar();
while(c<''||c>''){if(c=='-')flag=-;c=getchar();}
while(c>=''&&c<=''){num=num*+c-'';c=getchar();}
return num*flag;
}
bool cmp(const node&s1,const node&s2){
return s1.pos<s2.pos;
}
void push_up(lon x){
w[x]=w[son[x][]]+w[son[x][]];
sum[x]=sum[son[x][]]+sum[son[x][]];
}
void insert(lon x,lon &y,lon l,lon r,lon v){
y=++cn;
if(l==r){
if(v>) w[y]=w[x]+;
else w[y]=w[x]-;
sum[y]=sum[x]+v;
return;
}
son[y][]=son[x][];
son[y][]=son[x][];
lon mid=l+r>>;
if(abs(v)<=mid) insert(son[x][],son[y][],l,mid,v);
else insert(son[x][],son[y][],mid+,r,v);
push_up(y);
}
lon query(lon R,lon k){
lon x=root[R];
if(w[x]<=k)return sum[x];
lon l=,r=lim,ans=;
while(l<r){
lon mid=l+r>>;
if(w[son[x][]]>=k){
r=mid;
x=son[x][];
}
else {
ans+=sum[son[x][]];
k-=w[son[x][]];
l=mid+;
x=son[x][];
}
if(l>=r) return ans+sum[x]/w[x]*k;
}
return ans;
}
int main(){
n=read();m=read();
for(lon i=;i<=n;i++){
lon x=read(),y=read(),p=read();
e[++cnt].pos=x;e[cnt].v=p;
e[++cnt].pos=y+;e[cnt].v=-p;
lim=max(lim,p);
}
sort(e+,e+cnt+,cmp);
for(lon i=;i<=cnt;i++) insert(root[i-],root[i],,lim,e[i].v);
for(lon i=cnt;i>=;i--)
if(e[i].pos!=e[i+].pos)
to[e[i].pos]=i;
for(lon i=;i<=n;i++)
if(!to[i])to[i]=to[i-];
lon pre=;
for(lon i=;i<=m;i++){
lon x=read(),a=read(),b=read(),c=read();
lon k=(a*pre+b)%c+;
pre=query(to[x],k);
printf("%lld\n",pre);
}
return ;
}
任务查询系统(bzoj 3932)的更多相关文章
- 主席树||可持久化线段树||离散化||[CQOI2015]任务查询系统||BZOJ 3932||Luogu P3168
题目: [CQOI2015]任务查询系统 题解: 是一道很经典的题目.大体思路是抓优先级来当下标做主席树,用时刻作为主席树的版本.然而优先级范围到1e7去了,就离散化一遍.然后把每个事件的开始(s). ...
- 2018.06.30 BZOJ 3932: [CQOI2015]任务查询系统(主席树)
3932: [CQOI2015]任务查询系统 Time Limit: 20 Sec Memory Limit: 512 MB Description 最近实验室正在为其管理的超级计算机编制一套任务管理 ...
- bzoj 3932: [CQOI2015]任务查询系统 -- 主席树 / 暴力
3932: [CQOI2015]任务查询系统 Time Limit: 20 Sec Memory Limit: 512 MB Description 最近实验室正在为其管理的超级计算机编制一套任务管 ...
- 3932: [CQOI2015]任务查询系统
3932: [CQOI2015]任务查询系统 Time Limit: 20 Sec Memory Limit: 512 MBSubmit: 2559 Solved: 819[Submit][Sta ...
- BZOJ3932: [CQOI2015]任务查询系统 主席树
3932: [CQOI2015]任务查询系统 Time Limit: 20 Sec Memory Limit: 512 MBSubmit: 4869 Solved: 1652[Submit][St ...
- BZOJ3932: [CQOI2015]任务查询系统
传送门 真不知道我没学主席树之前是有什么勇气说自己高级数据结构以及学的七七八八了. 这道题应该也是算是主席树的经典运用. 刚开始脑抽了,想把(S,E,P)的处理直接在线用树状数组xjb搞搞算了.写完后 ...
- 【BZOJ3932】任务查询系统(主席树)
[BZOJ3923]任务查询系统(主席树) 题面 Description 最近实验室正在为其管理的超级计算机编制一套任务管理系统,而你被安排完成其中的查询部分.超级计算机中的 任务用三元组(Si,Ei ...
- BZOJ_3932_[CQOI2015]任务查询系统_主席树
BZOJ_3932_[CQOI2015]任务查询系统_主席树 题意: 最近实验室正在为其管理的超级计算机编制一套任务管理系统,而你被安排完成其中的查询部分.超级计算机中的 任务用三元组(Si,Ei,P ...
- P3168 [CQOI2015]任务查询系统
题目地址:P3168 [CQOI2015]任务查询系统 主席树的模板题 更模板的在这儿:P3834 [模板]可持久化线段树 1(主席树) 形象的说,P3834是"单点修改,区间查询" ...
- bzoj3932 / P3168 [CQOI2015]任务查询系统(主席树+差分)
P3168 [CQOI2015]任务查询系统 看到第k小,就是主席树辣 对于每一段任务(a,b,k),在版本a的主席树+k,版本b+1的主席树-k 同一时间可能有多次修改,所以开个vector存操作, ...
随机推荐
- AS 开发环境配置
安装时不用设置代理(proxy). 建议选择标准安装,自定义安装容易选掉一些功能.插件. SDK Tools里的(HAXM installer)有时会未安装,安装完需检查(HAXM installer ...
- laravel的scout包安装及laravel-es包安装
安装laravel/scout 作用:搜索驱动,可随时更换驱动,上层业务逻辑可不用改变 官网文档:https://laravel-china.org/docs/laravel/5.4/scout/12 ...
- codevs 2600 13号星期几?
时间限制: 1 s 空间限制: 8000 KB 题目等级 : 黄金 Gold 题目描述 Description 从1900年1月1日(星期一) 开始经过的n年当中,每个月的13号这一天是星期一.星 ...
- iview table icon dorpdown html页面级别vue组件 #vuez#
iview table icon dorpdown html页面级别vue组件 <!DOCTYPE html> <html> <head> <meta cha ...
- 关于sigleton模式
单例模式的要点有三个:一是某个类只能有一个实例:二是它必须自行创建这个实例:三是它必须自行向整个系统提供这个实例. 从具体实现角度来说,就是以下三点:一是单例模式的类只提供私有的构造函数,二是类定义中 ...
- myBatis的binding错误:Invalid bound statement (not found)
org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)错误这个问题我找了好久,终于找到了正确的写 ...
- AspNetCore容器化(Docker)部署(一) —— 入门
一.docker注册安装 Windows Docker Desktop https://www.docker.com/products/docker-desktop Linux Docker CE h ...
- JavaSE-28 hashCode()方法、equals()方法和==相关概念
概述 Java中,Object类是所有类的基类:如果一个类没有明确继承其他已定义的类,则默认继承Object类. Object类提供了以下方法,对于其他方法,请参考前期专题描述. hashCode() ...
- [ERROR ] Error parsing configuration file: /etc/salt/minion - conf should be a document, not <type 'str'>.
错误信息 [ERROR ] Error parsing configuration file: /etc/salt/minion - conf should be a document, not &l ...
- Python打包成exe,pyc
D:\mypython\path\ C:\Python27\Scripts\pyinstaller.exe -w mypython.py # Python打包成exe D:\mypython\path ...