Serge and Dining Room

改变选的顺序, 最后的结果不变。

这种题一般都和前缀和有关, 建个线段树维护前缀和就好了。

#include<bits/stdc++.h>
#define LL long long
#define LD long double
#define ull unsigned long long
#define fi first
#define se second
#define mk make_pair
#define PLL pair<LL, LL>
#define PLI pair<LL, int>
#define PII pair<int, int>
#define SZ(x) ((int)x.size())
#define ALL(x) (x).begin(), (x).end()
#define fio ios::sync_with_stdio(false); cin.tie(0);using namespace std;const int N = 1e6 + 7;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 7340033;
const double eps = 1e-8;
const double PI = acos(-1);template<class T, class S> inline void add(T &a, S b) {a += b; if(a >= mod) a -= mod;}
template<class T, class S> inline void sub(T &a, S b) {a -= b; if(a < 0) a += mod;}
template<class T, class S> inline bool chkmax(T &a, S b) {return a < b ? a = b, true : false;}
template<class T, class S> inline bool chkmin(T &a, S b) {return a > b ? a = b, true : false;}int n, m, a[N], b[N];const int maxVal = 1000000;
#define lson l, mid, rt << 1
#define rson mid + 1, r, rt << 1 | 1
struct segmentTree {int lazy[N << 2], mx[N << 2];inline void pull(int rt) {mx[rt] = max(mx[rt << 1], mx[rt << 1 | 1]);}inline void push(int rt) {if(lazy[rt]) {lazy[rt << 1] += lazy[rt];lazy[rt << 1 | 1] += lazy[rt];mx[rt << 1] += lazy[rt];mx[rt << 1 | 1] += lazy[rt];lazy[rt] = 0;}}void update(int L, int R, int val, int l = 1, int r = maxVal, int rt = 1) {if(R < l || r < L || R < L) return;if(L <= l && r <= R) {mx[rt] += val;lazy[rt] += val;return;}push(rt);int mid = l + r >> 1;update(L, R, val, lson);update(L, R, val, rson);pull(rt);}int query(int l = 1, int r = maxVal, int rt = 1) {if(mx[rt] <= 0) return -1;if(l == r) return l;push(rt);int mid = l + r >> 1;if(mx[rt << 1 | 1] > 0) return query(rson);else return query(lson);}
} Tree;int main() {scanf("%d%d", &n, &m);for(int i = 1; i <= n; i++) scanf("%d", &a[i]);for(int i = 1; i <= m; i++) scanf("%d", &b[i]);for(int i = 1; i <= n; i++) {Tree.update(1, a[i], 1);}for(int i = 1; i <= m; i++) {Tree.update(1, b[i], -1);}int q; scanf("%d", &q);while(q--) {int op, p, x;scanf("%d%d%d", &op, &p, &x);if(op == 1) {Tree.update(1, a[p], -1);a[p] = x;Tree.update(1, a[p], 1);} else {Tree.update(1, b[p], 1);b[p] = x;Tree.update(1, b[p], -1);}printf("%d\n", Tree.query());}return 0;
}/*
*/

转载于:https://www.cnblogs.com/CJLHY/p/11102793.html

Codeforces 1179C Serge and Dining Room 线段树相关推荐

  1. Codeforces 1004F Sonya and Bitwise OR (线段树)

    题目链接 https://codeforces.com/contest/1004/problem/F 题解 这种水题都不会做了怎么.. 考虑一个序列的前缀 \(\text{or}\) 值只会变化 \( ...

  2. CodeForces - 1529E Trees of Tranquillity(贪心+线段树)

    题目链接:https://vjudge.net/problem/CodeForces-1529E 题目大意:给出两棵根节点为 111 的树,分别称为 AAA 树和 BBB 树,现在通过两棵树可以构造出 ...

  3. Codeforces 1045. A. Last chance(网络流 + 线段树优化建边)

    题意 给你 \(n\) 个武器,\(m\) 个敌人,问你最多消灭多少个敌人,并输出方案. 总共有三种武器. SQL 火箭 - 能消灭给你集合中的一个敌人 \(\sum |S| \le 100000\) ...

  4. [codeforces] 383C Propagating tree(dfs序+线段树)

    题意: 给你一棵n个结点的树, 以1为根.每个结点有点权.有m次操作: 1.x结点权值 +val,x的儿子权值 −val,x的孙子们 +val,以此类推. 2.询问x的点权: 题解: 我们首先跑一边d ...

  5. CodeForces - 1217F Forced Online Queries Problem(线段树分治+并查集撤销)

    题目链接:点击查看 题目大意:给出 nnn 个点,初始时互相不存在连边,需要执行 mmm 次操作,每次操作分为两种类型: 1xy1 \ x \ y1 x y:如果 (x,y)(x,y)(x,y) 之间 ...

  6. CodeForces - 504B Misha and Permutations Summation(线段树模拟康托展开与逆展开)

    题目链接:点击查看 题目大意:给出两个排列 ppp 和 qqq,现在要求输出 Perm((Ord(p)+Ord(q))modn!)Perm((Ord(p)+Ord(q)) \bmod n!) Perm ...

  7. codeforces CF438D The Child and Sequence 线段树

    $ \Rightarrow $ 戳我进CF原题 D. The Child and Sequence time limit per test: 4 seconds memory limit per te ...

  8. 【CodeForces - 527C】Glass Carving(线段树或者SBT或者set)

    题干: Leonid wants to become a glass carver (the person who creates beautiful artworks by cutting the ...

  9. Codeforces.700E.Cool Slogans(后缀自动机 线段树合并 DP)

    题目链接 \(Description\) 给定一个字符串\(s[1]\).一个字符串序列\(s[\ ]\)满足\(s[i]\)至少在\(s[i-1]\)中出现过两次(\(i\geq 2\)).求最大的 ...

最新文章

  1. 不妨对苹果保持一点宽容
  2. Python3爬虫之爬取某一路径的所有html文件
  3. 【Go语言】使用 http 库进行简单的接口测试
  4. 9.10 nohup:用户退出系统进程继续工作
  5. solaris 10 安装Apache Mysql PHP
  6. javascript第三天(2)
  7. matlab遗传算法实例crtrp,遗传算法求解实例
  8. 解读顶会CIKM‘21 Historical Inertia论文
  9. php堆栈溢出,php - 警告:php_eval() - 堆栈内存溢出
  10. LINUX-iostat命令讲解
  11. 我的2017OKR - 年中回顾
  12. 资深大学老师告诉你:嵌入式、单片机开发必备软件有哪些
  13. js调用html文件上传,JavaScript里的文件上传API
  14. 滤波器截止频率理解?
  15. Caddy服务器代理
  16. 【蓝桥杯真题训练 day14】今日四道真题全解析
  17. 如何清理华为云空间的照片
  18. 关于 *.csproj: 找不到此项目类型所基于的应用程序 的解决方案
  19. 微型计算机的型号是奔四800,第1章 微型计算机基础知识
  20. Shell Perl Python 脚本语言介绍

热门文章

  1. 蓝牙技术|智能蓝牙芯片助力元宇宙发展
  2. 基于Javaweb的问卷调查系统
  3. 小程序微信授权登录服务器异常,微信小程序授权登录流程(强制绑定手机号码)...
  4. Android Studio 模拟器打不开解决方法
  5. 你以为打上马赛克就安全了吗?用Python一键还原,了解一下?
  6. Arduino ESP32Web配网
  7. uniapp写一个登录页面
  8. Scala中TypeTags和Manifests的用法
  9. HBaseCon Asia 2019 Track 3 概要回顾
  10. pdo 参数绑定中 where 子句中的错误的解决