Educational Codeforces Round 23 F. MEX Queries(线段树)
题目链接:Educational Codeforces Round 23 F. MEX Queries
题意:
一共有n个操作。
1. 将[l,r]区间的数标记为1。
2. 将[l,r]区间的数标记为0。
3. 将[l,r]区间取反。
对每个操作,输出标记为0的最小正整数。
题解:
hash后,用线段树xjb标记一下就行了。
1 #include<bits/stdc++.h> 2 #define ls l,m,rt<<1 3 #define rs m+1,r,rt<<1|1 4 #define F(i,a,b) for(int i=a;i<=b;++i) 5 using namespace std; 6 typedef long long ll; 7 8 const int N=4e5+7; 9 int n,ed,sum[N<<2],lazy[N<<2]; 10 ll hsh[N],mx; 11 struct Node 12 { 13 int type; 14 ll l,r; 15 }q[N]; 16 17 void del(int rt) 18 { 19 if(lazy[rt]==1||lazy[rt]==2)lazy[rt]=(lazy[rt]==1?2:1); 20 else if(lazy[rt]==3)lazy[rt]=0; 21 else lazy[rt]=3; 22 } 23 24 void PD(int rt,int l,int r) 25 { 26 if(!lazy[rt])return; 27 int m=l+r>>1; 28 if(lazy[rt]==1) 29 { 30 sum[rt<<1]=m-l+1,sum[rt<<1|1]=r-m; 31 lazy[rt<<1]=lazy[rt<<1|1]=1; 32 } 33 else if(lazy[rt]==2) 34 { 35 sum[rt<<1]=sum[rt<<1|1]=0; 36 lazy[rt<<1]=lazy[rt<<1|1]=2; 37 } 38 else 39 { 40 sum[rt<<1]=(m-l+1)-sum[rt<<1],sum[rt<<1|1]=(r-m)-sum[rt<<1|1]; 41 del(rt<<1),del(rt<<1|1); 42 } 43 lazy[rt]=0; 44 } 45 46 void PU(int rt){sum[rt]=sum[rt<<1]+sum[rt<<1|1];} 47 48 void update(int L,int R,int v,int l=1,int r=ed,int rt=1) 49 { 50 if(L<=l&&r<=R) 51 { 52 if(v==1)sum[rt]=(r-l+1),lazy[rt]=1; 53 else if(v==2)sum[rt]=0,lazy[rt]=2; 54 else del(rt),sum[rt]=(r-l+1)-sum[rt]; 55 return; 56 } 57 PD(rt,l,r); 58 int m=l+r>>1; 59 if(L<=m)update(L,R,v,ls); 60 if(R>m)update(L,R,v,rs); 61 PU(rt); 62 } 63 64 int query(int l=1,int r=ed,int rt=1) 65 { 66 if(l==r)return l; 67 int m=l+r>>1; 68 PD(rt,l,r); 69 if(m-l+1-sum[rt<<1])return query(ls); 70 else return query(rs); 71 } 72 73 74 int getid(ll x){return lower_bound(hsh+1,hsh+1+ed,x)-hsh;} 75 76 int main(){ 77 scanf("%d",&n); 78 F(i,1,n) 79 { 80 scanf("%d%I64d%I64d",&q[i].type,&q[i].l,&q[i].r); 81 hsh[++ed]=q[i].l,hsh[++ed]=q[i].r; 82 hsh[++ed]=q[i].l+1,hsh[++ed]=q[i].r+1; 83 } 84 hsh[++ed]=1; 85 sort(hsh+1,hsh+1+ed),ed=unique(hsh+1,hsh+1+ed)-hsh-1; 86 F(i,1,n) 87 { 88 update(getid(q[i].l),getid(q[i].r),q[i].type); 89 printf("%I64d\n",hsh[query()]); 90 } 91 return 0; 92 }
View Code
转载于:https://www.cnblogs.com/bin-gege/p/7061726.html
Educational Codeforces Round 23 F. MEX Queries(线段树)相关推荐
- Educational Codeforces Round 96 E. String Reversa 线段树模拟序列交换
传送门 文章目录 题意: 思路: 题意: 思路: 与上一篇题解大同小异,无非就是不需要枚举排列了. // Problem: E. String Reversal // Contest: Codefor ...
- CF Educational Round 23 F.MEX Queries
写了3小时 = =.这两天堕落了,昨天也刷了一晚上hihocoder比赛,还爆了零.之后得节制点了,好好准备考研.. 首先很容易想到 压缩数据 + 线段树 然后对于Pushdown真很难写..需要牵涉 ...
- Educational Codeforces Round 25 G. Tree Queries
题目链接:Educational Codeforces Round 25 G. Tree Queries 题意: 给你一棵树,一开始所有的点全是黑色,有两种操作. 1 x 将x这个点变为黑色,保证第一 ...
- Educational Codeforces Round 23:E. Choosing The Commander(字典树01异或)
Educational Codeforces Round 23:E. Choosing The Commander(字典树01异或) 题意: 3种操作: 1 插入一个数 2 删除一个数 3 给出一个数 ...
- CodeForces - 817F MEX Queries(线段树lazy序)
题目链接:点击查看 题目大意:初始时有一个空的集合,需要执行 n 次操作: 1 l r:将区间 [ l , r ] 内未出现的数加入到集合中 2 l r:将区间 [ l , r ] 内出现的数字全部删 ...
- 20.CF817F MEX Queries 线段树(Lazy标记练习)
20.CF817F MEX Queries 离散化+区间覆盖+区间反转线段树 个人Limitの线段树题单题解主目录:Limitの线段树题单 题解目录_HeartFireY的博客-CSDN博客 要求维护 ...
- Educational Codeforces Round 112 E.Boring Segments-线段树+双指针
https://codeforces.com/contest/1555/problem/E 这场的e好像比较简单. 题目大意,给你n个线段,最大点是m,每一个线段有一个权值w,你能选择线段来覆盖1-m ...
- Educational Codeforces Round 9 F. Magic Matrix 最小生成树
F. Magic Matrix 题目连接: http://www.codeforces.com/contest/632/problem/F Description You're given a mat ...
- Educational Codeforces Round 14 - F (codeforces 691F)
题目链接:http://codeforces.com/problemset/problem/691/F 题目大意:给定n个数,再给m个询问,每个询问给一个p,求n个数中有多少对数的乘积≥p 数据范围: ...
- Educational Codeforces Round 39 F Largest Beautiful Number
传送门 暴力DP dp[i][j][k] 从j 到 k 发f(x) 的大小, #include <bits/stdc++.h> using namespace std; typedef l ...
最新文章
- java-web测试题cpu_tomcat+java的web程序持续占cpu高问题调试【转】
- npm 装包时的区别 -D -S
- Cocos2d-x使用iOS游戏内付费IAP(C++篇)
- linux 为什么编译内核,Linux内核编译与安装
- 抢鲜体验.NET6 Preview1,配上Docker简直停不下来!
- 一文读懂经典卷积网络模型——LeNet-5模型(附代码详解、MNIST数据集)
- 特斯拉在华第900座超级充电站落户深圳
- linux嵌入式工作室,【课程培训】嵌入式linux驱动开发系列教程 | linux2web工作室...
- oracle 手动链库,Oracle 数据库干数据库链(Database links)的两个例子
- 51NOD 1623 完美消除 数位DP
- JAVA通过FDFS上传以及加载文件原理简析
- 用户·角色·权限·表
- BCB中嵌入资源文件的研究
- 安徽大学计算机复试刷人比例,658人进复试刷掉564多人!盘点21复试比奇高、刷人狠的院校专业...
- 三步棋,跟着bit鹏哥学得
- 前端学习-数据可视化(个人笔记)
- 我认识的七个理想主义者
- 曹胜欢,java那些事儿
- 美团网2015秋季校园招聘面试题(下)
- java 多线程垃圾回收_Java 垃圾回收