Educational Codeforces Round 23F
http://codeforces.com/contest/817/problem/F
无限长的数组,刚开始每一位是0,三种操作,1,把(l,r)之间不是1的变成1,2,把(l,r)之间不是0的变成0,3,把0变成1,1变成0,每次操作都要查询该数组的mex(最小的没有在集合中出现的数)
解法:很明显的线段树,lazy标记有3个,分别代表3中操作的,当pushdown的时候如果lazy为1或2都直接下传,但是当lazy是3的时候,不能直接下传,因为1,2操作优先级更大,所以pushdown时特判一下这种情况即可(当儿子的lazy为1时,刚好需要先全变1然后翻转就是2操作1了,lazy为2同理,lazy为3的话直接翻转两次等同于没有翻转),查询的话,直接查询左右区间,如果左区间是满的,那么右边,否则查询左侧,注意hash的时候把1加上去,每个点左右两个点也要加进去,不然会出现断层!!
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pi acos(-1.0)
#define ll long long
#define mod 1000000007
#define C 0.5772156649
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1
#define pil pair<int,ll>
#define pii pair<int,int>
#define ull unsigned long long
#define base 1000000000000000000
#define fio ios::sync_with_stdio(false);cin.tie(0) using namespace std; const double g=10.0,eps=1e-;
const int N=+,maxn=+,inf=0x3f3f3f3f,INF=0x3f3f3f3f3f3f3f3f; struct qu{
int t;
ll l,r;
}q[N];
int lazy[N<<],value[N<<];
int cnt;
ll Hash[N<<];
void pushup(int rt)
{
value[rt]=value[rt<<]+value[rt<<|];
}
void pushdown(int l,int r,int rt)
{
int m=(l+r)>>;
if(lazy[rt]==)
{
value[rt<<]=m-l+;
value[rt<<|]=r-m;
lazy[rt<<]=lazy[rt<<|]=;
}
else if(lazy[rt]==)
{
value[rt<<]=value[rt<<|]=;
lazy[rt<<]=lazy[rt<<|]=;
}
else if(lazy[rt]==)
{
value[rt<<]=m-l+-value[rt<<];
value[rt<<|]=r-m-value[rt<<|];
lazy[rt<<]=-lazy[rt<<];
lazy[rt<<|]=-lazy[rt<<|];
}
lazy[rt]=;
}
void build(int l,int r,int rt)
{
value[rt]=,lazy[rt]=;
if(l==r)return ;
int m=(l+r)>>;
build(ls);build(rs);
}
void update(int L,int R,int op,int l,int r,int rt)
{
if(L<=l&&r<=R)
{
if(op==)
{
value[rt]=r-l+;
lazy[rt]=op;
}
else if(op==)
{
value[rt]=;
lazy[rt]=op;
}
else
{
if(lazy[rt])pushdown(l,r,rt);
value[rt]=r-l+-value[rt];
lazy[rt]=op;
}
return ;
}
pushdown(l,r,rt);
int m=(l+r)>>;
if(L<=m)update(L,R,op,ls);
if(m<R)update(L,R,op,rs);
pushup(rt);
}
int query(int l,int r,int rt)
{
if(l==r)return l;
pushdown(l,r,rt);
int m=(l+r)>>;
if(value[rt<<]==m-l+)return query(rs);
else return query(ls);
}
void add(ll x)
{
if(x!=)Hash[cnt++]=x;
}
int main()
{
int n;
cnt=;
scanf("%d",&n);
for(int i=;i<n;i++)
{
scanf("%d%lld%lld",&q[i].t,&q[i].l,&q[i].r);
add(q[i].l-),add(q[i].l),add(q[i].l+);
add(q[i].r-),add(q[i].r),add(q[i].r+);
}
Hash[cnt++]=;
sort(Hash,Hash+cnt);
cnt=unique(Hash,Hash+cnt)-Hash;
// for(int i=0;i<cnt;i++)printf("%lld ",Hash[i]);
// puts("");
build(,cnt,);
for(int i=;i<n;i++)
{
int op=q[i].t;
int tel=lower_bound(Hash,Hash+cnt,q[i].l)-Hash;
int ter=lower_bound(Hash,Hash+cnt,q[i].r)-Hash;
update(tel+,ter+,q[i].t,,cnt,);
int ans=query(,cnt,);
// printf("%d %d %d\n",tel,ter,ans);
printf("%lld\n",Hash[ans-]);
}
return ;
}
/********************
1
2 854690110384167294 954215012997404774
********************/
Educational Codeforces Round 23F的更多相关文章
- [Educational Codeforces Round 16]E. Generate a String
[Educational Codeforces Round 16]E. Generate a String 试题描述 zscoder wants to generate an input file f ...
- [Educational Codeforces Round 16]D. Two Arithmetic Progressions
[Educational Codeforces Round 16]D. Two Arithmetic Progressions 试题描述 You are given two arithmetic pr ...
- [Educational Codeforces Round 16]C. Magic Odd Square
[Educational Codeforces Round 16]C. Magic Odd Square 试题描述 Find an n × n matrix with different number ...
- [Educational Codeforces Round 16]B. Optimal Point on a Line
[Educational Codeforces Round 16]B. Optimal Point on a Line 试题描述 You are given n points on a line wi ...
- [Educational Codeforces Round 16]A. King Moves
[Educational Codeforces Round 16]A. King Moves 试题描述 The only king stands on the standard chess board ...
- Educational Codeforces Round 6 C. Pearls in a Row
Educational Codeforces Round 6 C. Pearls in a Row 题意:一个3e5范围的序列:要你分成最多数量的子序列,其中子序列必须是只有两个数相同, 其余的数只能 ...
- Educational Codeforces Round 9
Educational Codeforces Round 9 Longest Subsequence 题目描述:给出一个序列,从中抽出若干个数,使它们的公倍数小于等于\(m\),问最多能抽出多少个数, ...
- Educational Codeforces Round 37
Educational Codeforces Round 37 这场有点炸,题目比较水,但只做了3题QAQ.还是实力不够啊! 写下题解算了--(写的比较粗糙,细节或者bug可以私聊2333) A. W ...
- Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship
Problem Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship Time Limit: 2000 mSec P ...
随机推荐
- <2014 04 29> c/c++常用库总结
C 标准库 ============================================================================================== ...
- AttachThreadInput
BOOL WINAPI AttachThreadInput( _In_ DWORD idAttach, _In_ DWORD idAttachTo, _In_ BOOL fAttach ); i ...
- cookies与session
一.cookies 本质:浏览器端保存的键值对 方便客户按照自己的习惯操作页面或软件,例如:用户验证,登陆界面,右侧菜单隐藏,控制页面列表显示条数... cookies是由服务端写在浏览器端,以后每次 ...
- 2015-03-12——简析DOM2级事件
DOM2级事件 事件的几种类型:对象事件,鼠标事件,键盘事件,表单事件,W3CDOM事件,以及针对浏览器的事件. 对象事件:window对象,也是javascript对象.load 适用于windo ...
- java基础08 双重循环打印图形
public class Double01 { /** * 若有3个班级各4名学员参赛, * 如何计算每个班级参赛学员的平均分? */ public static void main(String[] ...
- Python游戏引擎开发(五):Sprite精灵类和鼠标事件
本次来实现Sprite类和鼠标事件. 说起这个Sprite啊,涉及过2D游戏研究领域的看官应该都听说过它. 它中文原意是"精灵",只是在不同人的眼中,它所表示的意义不同. 比方说在 ...
- Kotlin开发Android笔记
外国人写的一个天气预报的例子,最后有源码下载地址,初学者可以研读一下 http://blog.csdn.net/true100/article/category/6257988 1:Kotlin介绍及 ...
- 怎么找出解析失败的sql
本文由我和公司同事问心共同测试分析完成. 很多时候我们会有这样一个误区,语法错误或者对象不存在应该在语法语义检查这个步骤就结束了,怎么还会存在共享池里面呢?带着这个几个问题我们做几个简单的测试. 我们 ...
- boost shared_ptr weak_ptr
文档: http://www.boost.org/doc/libs/1_57_0/libs/smart_ptr/shared_ptr.htm shared_ptr构造有个原型 template< ...
- Runtime.getRuntime().exec()需要注意的地方
文章出处http://www.cnblogs.com/fclbky/p/6112180.html 有时候我们可能需要调用系统外部的某个程序,此时就可以用Runtime.getRuntime().exe ...