绝对是很好的题

把问题转化成当第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好题的更多相关文章

  1. hdu 1556:Color the ball(线段树,区间更新,经典题)

    Color the ball Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)To ...

  2. ZOJ 2301 Color the Ball 线段树(区间更新+离散化)

    Color the Ball Time Limit: 2 Seconds      Memory Limit: 65536 KB There are infinite balls in a line ...

  3. hdu 1698:Just a Hook(线段树,区间更新)

    Just a Hook Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  4. 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 ...

  5. hdu1698线段树的区间更新区间查询

    Just a Hook Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Tota ...

  6. HDU 1556 Color the ball(线段树:区间更新)

    http://acm.hdu.edu.cn/showproblem.php?pid=1556 题意: N个气球,每次[a,b]之间的气球涂一次色,统计每个气球涂色的次数. 思路: 这道题目用树状数组和 ...

  7. zoj3686(线段树的区间更新)

    对线段树的区间更新有了初步的了解... A Simple Tree Problem Time Limit: 3 Seconds      Memory Limit: 65536 KB Given a ...

  8. Color the ball (线段树的区间更新问题)

    N个气球排成一排,从左到右依次编号为1,2,3....N.每次给定2个整数a b(a <= b),lele便为骑上他的“小飞鸽"牌电动车从气球a开始到气球b依次给每个气球涂一次颜色.但 ...

  9. Codeforces Gym 100733J Summer Wars 线段树,区间更新,区间求最大值,离散化,区间求并

    Summer WarsTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view.a ...

随机推荐

  1. C语言之文件包含

    c = #include <stdio.h> #include "A.h" int main() { /******************************** ...

  2. 【转】移动前端开发之viewport的深入理解

    原文链接:https://blog.csdn.net/u012402190/article/details/70172371 笔记 (20180919,目前暂且只看一部分)

  3. BBS论坛 home主页与个人站点主页

    五.Home主页与个人站点主页 home首页代码: # views.py视图函数部分代码def home(request): # 将数据库中的所有文章展示到主页 article_list = mode ...

  4. [工具]Editplus添加son格式化支持

    EditPlus安装包和json.js文件地址 不喜欢CSDN的积分下载和登录下载,不喜欢百度网盘,就这么倔强 https://github.com/michael-deve/CommonData-E ...

  5. mongo 分片集群的搭建

    MongoDB版本当前使用的MongoDB版本为4.2.0,下载地址.https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70-4.2. ...

  6. session之memcache

    nginx服务器配置:192.168.200.111[root@nginx ~]# hostname nginx[root@nginx ~]# bash[root@nginx ~]# vim /usr ...

  7. NX二次开发-UFUN添加工程图投影视图UF_DRAW_add_orthographic_view

    NX9+VS2012 #include <uf.h> #include <uf_draw.h> #include <uf_obj.h> #include <u ...

  8. Apache负载均衡

    Apache负载均衡 Apache也是可以实现负载均衡的.Apache的负载均衡主要是通过mod_proxy_balancer实现的.那么,apache负载均衡的配置方法是什么样的? 在apache的 ...

  9. ionic-CSS:ionic Toggle(切换开关)

    ylbtech-ionic-CSS:ionic Toggle(切换开关) 1.返回顶部 1. ionic Toggle(切换开关) 切换开关类似与 HTML 的 checkbox 标签,但它更易于在移 ...

  10. 信息安全-技术-Web:cookie

    ylbtech-信息安全-技术-Web:cookie Cookie,有时也用其复数形式 Cookies,指某些网站为了辨别用户身份.进行 session 跟踪而储存在用户本地终端上的数据(通常经过加密 ...