线段树离散化+区间更新——cf1179C好题
绝对是很好的题
把问题转化成当第i个询问的答案是数值x时是否可行
要判断值x是否可行,只要再将问题转化成a数组里>=x的值数量是否严格大于b数组里的>=x的值
那么线段树叶子结点维护对于值x的a数组里的合法数数量-b数组里的合法数数量,如果是正数即这个值可行
线段树维护区间最大值,然后询问最靠右的非负叶子下标
#include<bits/stdc++.h>
#include<vector>
using namespace std;
#define maxn 1000005 int Q,n,m,a[maxn],b[maxn],ans[maxn];
struct Query{int op,i,x;}q[maxn];
vector<int>v; #define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
int lazy[maxn<<],Max[maxn<<];
void pushdown(int rt){
if(lazy[rt]!=){
Max[rt<<]+=lazy[rt];
Max[rt<<|]+=lazy[rt];
lazy[rt<<]+=lazy[rt];
lazy[rt<<|]+=lazy[rt];
lazy[rt]=;
}
}
void pushup(int rt){
Max[rt]=max(Max[rt<<],Max[rt<<|]);
}
void update(int L,int R,int val,int l,int r,int rt){
if(L<=l && R>=r){
lazy[rt]+=val;
Max[rt]+=val;
return;
}
pushdown(rt);
int m=l+r>>;
if(L<=m)update(L,R,val,lson);
if(R>m)update(L,R,val,rson);
pushup(rt);
}
int query(int l,int r,int rt){
if(Max[rt]<=)return -;
if(l==r && Max[rt]>)return l;
pushdown(rt);
int m=l+r>>;
if(Max[rt<<|]>)
return query(rson);
else if(Max[rt<<]>)
return query(lson);
else return -;
} int main(){
cin>>n>>m;
for(int i=;i<=n;i++)scanf("%d",&a[i]),v.push_back(a[i]);
for(int i=;i<=m;i++)scanf("%d",&b[i]),v.push_back(b[i]);
cin>>Q;
for(int i=;i<=Q;i++){
scanf("%d%d%d",&q[i].op,&q[i].i,&q[i].x);
v.push_back(q[i].x);
} sort(v.begin(),v.end());
v.erase(unique(v.begin(),v.end()),v.end());
int nn=v.size(); for(int i=;i<=n;i++){
int pos=lower_bound(v.begin(),v.end(),a[i])-v.begin()+;
update(,pos,,,nn,);
}
for(int i=;i<=m;i++){
int pos=lower_bound(v.begin(),v.end(),b[i])-v.begin()+;
update(,pos,-,,nn,);
} for(int i=;i<=Q;i++){
int op=q[i].op,p=q[i].i,x=q[i].x;
if(op==){//修改a的值
int pos=lower_bound(v.begin(),v.end(),a[p])-v.begin()+;
update(,pos,-,,nn,);
a[p]=x;
pos=lower_bound(v.begin(),v.end(),a[p])-v.begin()+;
update(,pos,,,nn,);
ans[i]=query(,nn,);
if(ans[i]>)
ans[i]=v[ans[i]-];
}
else {
int pos=lower_bound(v.begin(),v.end(),b[p])-v.begin()+;
update(,pos,,,nn,);
b[p]=x;
pos=lower_bound(v.begin(),v.end(),b[p])-v.begin()+;
update(,pos,-,,nn,);
ans[i]=query(,nn,);
if(ans[i]>)
ans[i]=v[ans[i]-];
}
}
for(int i=;i<=Q;i++)
cout<<ans[i]<<'\n';
}
线段树离散化+区间更新——cf1179C好题的更多相关文章
- hdu 1556:Color the ball(线段树,区间更新,经典题)
Color the ball Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- ZOJ 2301 Color the Ball 线段树(区间更新+离散化)
Color the Ball Time Limit: 2 Seconds Memory Limit: 65536 KB There are infinite balls in a line ...
- hdu 1698:Just a Hook(线段树,区间更新)
Just a Hook Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- UVA 12436-Rip Van Winkle's Code(线段树的区间更新)
题意: long long data[250001]; void A( int st, int nd ) { for( int i = st; i \le nd; i++ ) data[i] = da ...
- hdu1698线段树的区间更新区间查询
Just a Hook Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tota ...
- HDU 1556 Color the ball(线段树:区间更新)
http://acm.hdu.edu.cn/showproblem.php?pid=1556 题意: N个气球,每次[a,b]之间的气球涂一次色,统计每个气球涂色的次数. 思路: 这道题目用树状数组和 ...
- zoj3686(线段树的区间更新)
对线段树的区间更新有了初步的了解... A Simple Tree Problem Time Limit: 3 Seconds Memory Limit: 65536 KB Given a ...
- Color the ball (线段树的区间更新问题)
N个气球排成一排,从左到右依次编号为1,2,3....N.每次给定2个整数a b(a <= b),lele便为骑上他的“小飞鸽"牌电动车从气球a开始到气球b依次给每个气球涂一次颜色.但 ...
- Codeforces Gym 100733J Summer Wars 线段树,区间更新,区间求最大值,离散化,区间求并
Summer WarsTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view.a ...
随机推荐
- EtherCat开源主站SOEM在windows下工程配置
截至2019年1月,虽然github上有1.3.3的更新,但是用的人估计还不多,而且1.3.2被官方认为bug严重弃用.所以还是学习1.3.1. 1.拷贝osal.oshw.soem.lib(已生成l ...
- web 服务中上传文件大小控制
参考文章:https://rensanning.iteye.com/blog/2388353 项目场景: Vue + Nginx + Java + Tomcat Nginx作为反向代理服务器,访问To ...
- python中while与else的联姻
循环使用 else 语句在 python 中,for … else 表示这样的意思,for 中的语句和普通的没有区别,else 中的语句会在循环正常执行完(即 for 不是通过 break 跳出而中断 ...
- JS自运行函数的写法和MVVM框架数据驱动的底层逻辑
1.JS自运行函数的写法 ( function(){ console.log(111)} )( ) !function(){ console.log(111) }() ( function(){}() ...
- leetcode-132-分割回文串②*
题目描述: 方法一:动态规划 class Solution: def minCut(self, s: str) -> int: min_s = list(range(len(s))) n = l ...
- 干货满满!解密阿里云RPA (机器人流程自动化)的产品架构和商业化发展
阿里云RPA,作为阿里云自研8年的技术,在资本的热捧下,逐渐从幕后来到台前,成为企业服务市场的黑马.本文将从产品上全面剖析,阿里云RPA这款产品的现阶段情况,同时简单谈谈阿里云RPA的商业化进展. 阿 ...
- vue.js 2.0 --- 安装node环境,webpack和脚手架(入门篇)
1.环境搭建 1.1.安装node.js 1.2 安装过程很简单,一路“下一步”就可以了.安装完成之后,打开命令行工具(win+r,然后输入cmd),输入 node -v,如下图,如果出现相应的版本号 ...
- Java-Class-@I:org.springframework.validation.annotation.Validated
ylbtech-Java-Class-@I:org.springframework.validation.annotation.Validated 1.返回顶部 2.返回顶部 1. package ...
- 微信-小程序-开发文档-服务端-模板消息:templateMessage.getTemplateList
ylbtech-微信-小程序-开发文档-服务端-模板消息:templateMessage.getTemplateList 1.返回顶部 1. templateMessage.getTemplateLi ...
- Centos 6 & Centos 7安装rabbitmq3.6.15(单节点)
系统准备 安装 erlang 语言环境 安装rabbitmq 配置网页插件 配置访问账号密码和权限 系统准备 centos6.5 与 centos7 都可以 ###安装依赖文件 yum -y inst ...