https://codeforces.com/contest/1180/problem/E

转载自他人博客

题意
有nn个菜肴,有mm个小朋友,每个菜肴的价格为aiai,每个小朋友有bibi元钱,小朋友从1→m1→m依次购买菜肴,当第ii个小朋友轮到的时候,他会购买他买的起的最贵的,否则就离开。
要求支持修改第ii个菜肴的价格和修改第ii个小朋友的拥有的钱数的两种操作,每次操作完成给出mm个小朋友买完后剩下的最贵的菜肴的价格是多少。

思路
假设价格大于xx的yy个菜肴都被买了,那么显然拥有钱数≥x≥x的小朋友个数一定要≥y≥y,显然如何购买是无所谓的。
那么就在aiai处减一,bibi处加一,每次询问一个最大的ll使得[l,∞][l,∞]的最大后缀和>0>0。
线段树维护即可。

代码

 #include<bits/stdc++.h>
#define clr(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long ll;
const int maxn=;
int n,m,q;
int sum[maxn<<],maxx[maxn<<];
int a[maxn],b[maxn];
void update(int o,int l,int r,int p,int val){
if(l==r){
sum[o]+=val;
maxx[o]+=val;
return;
}
int mid=(l+r)>>;
if(p<=mid)update(o<<,l,mid,p,val);
else update(o<<|,mid+,r,p,val);
sum[o]=sum[o<<]+sum[o<<|];
maxx[o]=max(maxx[o<<|],maxx[o<<]+sum[o<<|]);
//这里的每一个maxx,都是对应的 区间最大后缀和 但不是整根数轴的最大后缀和。
}
struct node{
int max,sum;
};
int query(int o,int l,int r,node tep){
if(l==r){
return l;
}
int mid=(l+r)>>;
node tep2;
tep2.sum=tep.sum+sum[o<<|];
tep2.max=maxx[o<<|]+tep.sum;//将标号为o这段区间的后面一段(o+1)的影响合并到o区间中
if(tep2.max>){
return query(o<<|,mid+,r,tep);
}
else{
return query(o<<,l,mid,tep2);
}
}
int main(){
while(cin>>n>>m){
clr(sum,),clr(maxx,);
for(int i=;i<=n;i++){
scanf("%d",&a[i]);
update(,,maxn-,a[i],);
}
for(int i=;i<=m;i++){
scanf("%d",&b[i]);
update(,,maxn-,b[i],-);
}
cin>>q;
while(q--){
int op,pos,val;
scanf("%d%d%d",&op,&pos,&val);
if(op==){
update(,,maxn-,a[pos],-);
update(,,maxn-,a[pos]=val,);
}else{
update(,,maxn-,b[pos],);
update(,,maxn-,b[pos]=val,-);
}
if(maxx[]<=)puts("-1");
else printf("%d\n",query(,,maxn-,{,}));
}
}
}

E - Serge and Dining Room的更多相关文章

  1. Codeforces 1180E Serge and Dining Room

    题意: 有\(n\)个菜肴,有\(m\)个小朋友,每个菜肴的价格为\(a_i\),每个小朋友有\(b_i\)元钱,小朋友从\(1 \rightarrow m\)依次购买菜肴,当第\(i\)个小朋友轮到 ...

  2. codeforces 1180E Serge and Dining Room 线段树

    题目传送门 题目大意: 给出a序列和b序列,a序列为各种食物的价格,b序列为一列排着队的小朋友拥有的钱,小朋友依次购买食物,每个人都买自己能买的起的最贵的食物,买不起就离开队伍.给出q次操作,操作1是 ...

  3. Codeforces Round #569 题解

    Codeforces Round #569 题解 CF1179A Valeriy and Deque 有一个双端队列,每次取队首两个值,将较小值移动到队尾,较大值位置不变.多组询问求第\(m\)次操作 ...

  4. BZOJ 1711: [Usaco2007 Open]Dining吃饭

    1711: [Usaco2007 Open]Dining吃饭 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 902  Solved: 476[Submit ...

  5. BZOJ 1226: [SDOI2009]学校食堂Dining

    1226: [SDOI2009]学校食堂Dining Time Limit: 10 Sec  Memory Limit: 259 MBSubmit: 730  Solved: 446[Submit][ ...

  6. poj3281 Dining

    Dining Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 14316   Accepted: 6491 Descripti ...

  7. [CareerCup] 16.3 Dining Philosophers 哲学家聚餐问题

    16.3 In the famous dining philosophers problem, a bunch of philosophers are sitting around a circula ...

  8. POJ 3281 Dining

    Dining Description Cows are such finicky eaters. Each cow has a preference for certain foods and dri ...

  9. BZOJ-1226 学校食堂Dining 状态压缩DP

    1226: [SDOI2009]学校食堂Dining Time Limit: 10 Sec Memory Limit: 259 MB Submit: 588 Solved: 360 [Submit][ ...

随机推荐

  1. tensorflow张量排序

    本篇记录一下TensorFlow中张量的排序方法 tf.sort和tf.argsort # 声明tensor a是由1到5打乱顺序组成的 a = tf.random.shuffle(tf.range( ...

  2. bugkuCTF-管理员系统(IP伪造)

    题目地址:http://123.206.31.85:1003/ 登进去是一个管理员后台登录的样子 试了sql的万能密码,发现进不了,而且下面还报错了ip禁止 禁止了我们的ip,但是他本地的ip肯定没有 ...

  3. python之路(集合,深浅copy,基础数据补充)

    一.集合:类似列表,元组的存储数据容器,不同点是不可修改,不可重复.无序排列. 1.创建集合: (1).set1 = {'abby', 'eric'} result:{'eric', 'abby'} ...

  4. LeetCode 836. 矩形重叠

    题目链接:https://leetcode-cn.com/problems/rectangle-overlap/ 矩形以列表 [x1, y1, x2, y2] 的形式表示,其中 (x1, y1) 为左 ...

  5. xampp安装配置比较容易卡住的地方

    xampp作为一款集成建站软件,方便了不少初学的开发者,但是虽然是集成和傻瓜式的安装,还是会遇到一些容易卡壳的地方,这里记录自己觉得一些比较重要的东西. 1.端口问题 如图是我改之后的端口,原来端口为 ...

  6. 用 ArcMap 发布 ArcGIS Server Feature Server Feature Access 服务 SQL Server版

    1. 安装Desktop, 2. 安装ArcGIS Server 3. 安装SQLServer2017 4. ArcMap 中 Catalog 中注册ArcGIS Server 5. System T ...

  7. python3练习100题——038

    原题链接:http://www.runoob.com/python/python-exercise-example38.html 题目:求一个3*3矩阵主对角线元素之和. 程序分析:利用双重for循环 ...

  8. ansi sql 语法 切换为 oracle 语法

        语句粘贴到 工作表 打开查询构建器 勾选 创建oracle连接 over     sql dev 的语法设置调整,否则表别名会右对齐   下面是 转换后的结果,是不是看得舒服多了

  9. The Softmax function and its derivative

    https://eli.thegreenplace.net/2016/the-softmax-function-and-its-derivative/  Eli Bendersky's website ...

  10. Appium学习2-Appium-desktop的使用

    安装: 下载路径:https://github.com/appium/appium-desktop/releases 选择最新的安装包即可. 使用 1.点击打开应用程序,进入到配置项. 2.配置以下信 ...