Educational Codeforces Round 23 F. MEX Queries 离散化+线段树
2 seconds
256 megabytes
standard input
standard output
You are given a set of integer numbers, initially it is empty. You should perform n queries.
There are three different types of queries:
- 1 l r — Add all missing numbers from the interval [l, r]
- 2 l r — Remove all present numbers from the interval [l, r]
- 3 l r — Invert the interval [l, r] — add all missing and remove all present numbers from the interval [l, r]
After each query you should output MEX of the set — the smallest positive (MEX ≥ 1) integer number which is not presented in the set.
The first line contains one integer number n (1 ≤ n ≤ 105).
Next n lines contain three integer numbers t, l, r (1 ≤ t ≤ 3, 1 ≤ l ≤ r ≤ 1018) — type of the query, left and right bounds.
Print MEX of the set after each query.
3
1 3 4
3 1 6
2 1 3
1
3
1
4
1 1 3
3 5 6
2 4 4
3 1 6
4
4
4
1
Here are contents of the set after each query in the first example:
- {3, 4} — the interval [3, 4] is added
- {1, 2, 5, 6} — numbers {3, 4} from the interval [1, 6] got deleted and all the others are added
- {5, 6} — numbers {1, 2} got deleted
题意:给你n个区间,1操作表示把[l,r]赋值为1,2操作表示把[l,r]赋值为0,3操作表示把[l,r]异或1;
求第一个不为0的正整数。
思路:对于所有区间[l,r]取出l,r,r+1三个点;
离散化放入线段树中去
现在需要区间修改,区间异或,查询
需要两个lazy标记,一个存修改的值,一个存是否异或1.
区间查询log查找即可,详见代码。
小trick:需要加入最小值,即是1的情况;
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<queue>
#include<algorithm>
#include<stack>
#include<cstring>
#include<vector>
#include<list>
#include<set>
#include<map>
#include<bitset>
#include<time.h>
using namespace std;
#define LL long long
#define pi (4*atan(1.0))
#define eps 1e-4
#define bug(x) cout<<"bug"<<x<<endl;
const int N=3e5+,M=4e6+,inf=,mod=1e9+;
const LL INF=1e18+,MOD=1e9+; int L=3e5+;
struct LT
{
int sum[N<<],to[N<<],sw[N<<];
void pushdown(int pos,int l,int r)
{
int mid=(l+r)>>;
if(to[pos]!=-)
{
to[pos<<]=to[pos];
to[pos<<|]=to[pos];
sum[pos<<]=to[pos]*(mid-l+);
sum[pos<<|]=to[pos]*(r-mid);
to[pos]=-;
sw[pos]=;
}
if(sw[pos])
{
if(to[pos<<]!=-)to[pos<<]=!to[pos<<];
else sw[pos<<]=!sw[pos<<];
if(to[pos<<|]!=-)to[pos<<|]=!to[pos<<|];
else sw[pos<<|]=!sw[pos<<|];
sum[pos<<]=(mid-l+)-sum[pos<<];
sum[pos<<|]=(r-mid)-sum[pos<<|];
sw[pos]=;
}
}
void build(int l,int r,int pos)
{
to[pos]=-;
sw[pos]=;
sum[pos]=;
if(l==r)return;
int mid=(l+r)>>;
build(l,mid,pos<<);
build(mid+,r,pos<<|);
}
void update(int L,int R,int c,int l,int r,int pos)
{
if(L<=l&&r<=R)
{
if(c==)
{
if(to[pos]!=-)to[pos]=!to[pos];
else sw[pos]=!sw[pos];
}
else
{
to[pos]=c;
sw[pos]=;
}
if(c==)sum[pos]=r-l+-sum[pos];
else sum[pos]=(r-l+)*c;
return;
}
pushdown(pos,l,r);
int mid=(l+r)>>;
if(L<=mid)update(L,R,c,l,mid,pos<<);
if(R>mid) update(L,R,c,mid+,r,pos<<|);
sum[pos]=sum[pos<<|]+sum[pos<<];
}
int query(int l,int r,int pos)
{
//cout<<l<<" "<<r<<" "<<sum[pos]<<" "<<to[pos]<<endl;
if(l==r)return l;
pushdown(pos,l,r);
//cout<<sum[pos<<1]<<" "<<sum[pos<<1|1]<<endl;
int mid=(l+r)>>;
if(sum[pos<<]==mid-l+)return query(mid+,r,pos<<|);
else return query(l,mid,pos<<);
}
}tree; int t[N],len;
LL l[N],r[N],s[N];
int getpos(LL x)
{
int pos=lower_bound(s+,s+len,x)-s;
return pos;
}
int main()
{
int n,k=;
scanf("%d",&n);
s[++k]=;
for(int i=;i<=n;i++)
scanf("%d%lld%lld",&t[i],&l[i],&r[i]),s[++k]=l[i],s[++k]=r[i],s[++k]=r[i]+;
sort(s+,s++k);
len=unique(s+,s++k)-s;
tree.build(,L,);
for(int i=;i<=n;i++)
{
int z=getpos(l[i]),y=getpos(r[i]);
if(t[i]==)tree.update(z,y,,,L,);
else if(t[i]==)tree.update(z,y,,,L,);
else if(t[i]==)tree.update(z,y,,,L,);
int x=tree.query(,L,);
//cout<<"xxx "<<x<<" "<<tree.sum[1]<<endl;
printf("%lld\n",s[x]);
}
return ;
}
Educational Codeforces Round 23 F. MEX Queries 离散化+线段树的更多相关文章
- [Codeforces]817F. MEX Queries 离散化+线段树维护
[Codeforces]817F. MEX Queries You are given a set of integer numbers, initially it is empty. You sho ...
- Educational Codeforces Round 37-F.SUM and REPLACE (线段树,线性筛,收敛函数)
F. SUM and REPLACE time limit per test2 seconds memory limit per test256 megabytes inputstandard inp ...
- Educational Codeforces Round 64 (Rated for Div. 2) (线段树二分)
题目:http://codeforces.com/contest/1156/problem/E 题意:给你1-n n个数,然后求有多少个区间[l,r] 满足 a[l]+a[r]=max([l, ...
- CF Educational Round 23 F.MEX Queries
写了3小时 = =.这两天堕落了,昨天也刷了一晚上hihocoder比赛,还爆了零.之后得节制点了,好好准备考研.. 首先很容易想到 压缩数据 + 线段树 然后对于Pushdown真很难写..需要牵涉 ...
- Educational Codeforces Round 40 F. Runner's Problem
Educational Codeforces Round 40 F. Runner's Problem 题意: 给一个$ 3 * m \(的矩阵,问从\)(2,1)$ 出发 走到 \((2,m)\) ...
- Educational Codeforces Round 23 A-F 补题
A Treasure Hunt 注意负数和0的特殊处理.. 水题.. 然而又被Hack了 吗的智障 #include<bits/stdc++.h> using namespace std; ...
- Educational Codeforces Round 23 补题小结
昨晚听说有教做人场,去补了下玩. 大概我的水平能做个5/6的样子? (不会二进制Trie啊,我真菜) A. 傻逼题.大概可以看成向量加法,判断下就好了. #include<iostream> ...
- 【Educational Codeforces Round 37 F】SUM and REPLACE
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 那个D函数它的下降速度是很快的. 也就是说到最后他会很快的变成2或者1 而D(2)==2,D(1)=1 也就是说,几次操作过后很多数 ...
- Codeforces Codeforces Round #316 (Div. 2) C. Replacement 线段树
C. ReplacementTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/570/problem ...
随机推荐
- 51nod 1130 N的阶乘的长度 V2(斯特林近似)
输入N求N的阶乘的10进制表示的长度.例如6! = 720,长度为3. Input 第1行:一个数T,表示后面用作输入测试的数的数量.(1 <= T <= 1000) 第2 - T + ...
- 可视化的fineBI很高大上 使用简单,简单操作了一下,拖一拖就行,收费 只能看一下人家的demo 网站 http://demo.finebi.com/webroot/decision#directory
- 垂直打击之JVM剖析
让Java应用程序运行是一回事,但让他们跑得快就是另外一回事了.在面对对象的环境中,性能问题就像来势凶猛的野兽.但JVM的复杂性将性能调整的复杂程度增加了一个级别.这里Refcard涵盖了JVM in ...
- MySQL 如何创建索引?怎么优化?
索引类似大学图书馆建书目索引,可以提高数据检索的效率,降低数据库的IO成本.MySQL在300万条记录左右性能开始逐渐下降,虽然官方文档说500~800w记录,所以大数据量建立索引是非常有必要的.My ...
- K8S学习笔记之Kubernetes核心概念
0x00 Kubernetes简介 Kubernetes(K8S)是Google开源的容器集群管理系统,其设计源于Google在容器编排方面积累的丰富经验,并结合社区创新的最佳实践. K8S在Doc ...
- Golang实现冒泡排序法
关于冒泡排序的原理请看本博客这篇文章冒泡排序法原理讲解及PHP代码示例 //代码 package main import ( "fmt" ) func main() { //定义一 ...
- UUID实现之一twitter的分布式自增IDsnowflake算法
Twitter的分布式自增ID算法snowflake (Java版) 概述 分布式系统中,有一些需要使用全局唯一ID的场景,这种时候为了防止ID冲突可以使用36位的UUID,但是UUID有一些缺点 ...
- Python 自学基础(一)——元组 字典 文件操作
格式化输出 name = input("请输入你的名字:") age = input("请输入你的年龄:") msg = ''' -------------in ...
- QT---实现舒尔特方格(零基础入门)
按照之前说的,加上舒尔特方格,读者还可以自行将此游戏做成APP放到手机上,后面还有贪吃蛇,Java版的飞机大战,五子棋,各类游戏会不断加上来的,当然,会免费附加源代码! 读者可以去4399去玩一下,可 ...
- bzoj 1014 火星人prefix - 链表 - 分块
Description 火星人最近研究了一种操作:求一个字串两个后缀的公共前缀.比方说,有这样一个字符串:madamimadam,我们将这个字符串的各个字符予以标号:序号: 1 2 3 4 5 6 7 ...