线段树离散化+区间更新——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 ...
随机推荐
- Java支持的数据类型有哪些?什么是拆装箱?
Java中有八种基本数据类型以及引用类型 基本数据类型: byte(1字节),short(2字节),int(4字节),long(8字节),char(2字节),boolean(不确定,取值是true/f ...
- 前端自动化构建工具——gulp环境搭建教程
gulp是前端工程化的工具,它可以对html,css,js等代码和图片进行压缩,也可以对sass和less等预处理语言进行编译,代码部署.gulp学起来简单,用起来方便,大大提高我们工作效率. 这里可 ...
- 转: Meshlab简介
本文翻译自Meshlab主页:http://www.meshlab.net/ MeshLab是用于处理和编辑3D三角形网格的开源系统.它提供了一组用于编辑,清理,修复,检查,渲染,纹理和转换网格的工具 ...
- 覆盖element ui 的样式
我们可以使用 !important 来覆盖element ui 的样式 首先先在浏览器中找到 我们所要修改的样式 ,然后找到她的 class 重新写他的样式 ,例如 . app { width ...
- vue 学习四 了解组件
1组件的注册 全局注册 import Vue from 'vue'; import com from './component1'; Vue.component("com_name" ...
- leetcood学习笔记-437-路径总和③**
题目描述: 方法一:栈 class Solution(object): def pathSum(self, root, sum): """ :type root: Tre ...
- Cucumber:启动类配置
Cucumber:启动类配置 package com.steps; import cucumber.api.CucumberOptions; import cucumber.api.junit.Cuc ...
- thinkphp 动态配置
之前的方式都是通过预先定义配置文件的方式,而在具体的操作方法里面,我们仍然可以对某些参数进行动态配置(或者增加新的配置),主要是指那些还没有被使用的参数. 设置新的值: C('参数名称','新的参数值 ...
- 牛客多校第十场 D Han Xin and His Troops 中国剩余定理
题意: 韩信有若干个兵,给定你若干个模数和余数,再给你一个1e18以内的范围限制,求解同余方程组,如果无解,输出“他一定在撒谎”,如果最小解超出范围限制,输出“他可能在撒谎”,否则输出最小解 注意:不 ...
- hdu多校第五场1006 (hdu6629) string matching Ex-KMP
题意: 给你一个暴力匹配字符串公共前缀后缀的程序,为你对于某个字符串,暴力匹配的次数是多少. 题解: 使用扩展kmp构造extend数组,在扩展kmp中,设原串S和模式串T. extend[i]表示T ...