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加上去,每个点左右两个点也要加进去,不然会出现断层!!

  1. //#pragma comment(linker, "/stack:200000000")
  2. //#pragma GCC optimize("Ofast,no-stack-protector")
  3. //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
  4. //#pragma GCC optimize("unroll-loops")
  5. #include<bits/stdc++.h>
  6. #define fi first
  7. #define se second
  8. #define mp make_pair
  9. #define pb push_back
  10. #define pi acos(-1.0)
  11. #define ll long long
  12. #define mod 1000000007
  13. #define C 0.5772156649
  14. #define ls l,m,rt<<1
  15. #define rs m+1,r,rt<<1|1
  16. #define pil pair<int,ll>
  17. #define pii pair<int,int>
  18. #define ull unsigned long long
  19. #define base 1000000000000000000
  20. #define fio ios::sync_with_stdio(false);cin.tie(0)
  21.  
  22. using namespace std;
  23.  
  24. const double g=10.0,eps=1e-;
  25. const int N=+,maxn=+,inf=0x3f3f3f3f,INF=0x3f3f3f3f3f3f3f3f;
  26.  
  27. struct qu{
  28. int t;
  29. ll l,r;
  30. }q[N];
  31. int lazy[N<<],value[N<<];
  32. int cnt;
  33. ll Hash[N<<];
  34. void pushup(int rt)
  35. {
  36. value[rt]=value[rt<<]+value[rt<<|];
  37. }
  38. void pushdown(int l,int r,int rt)
  39. {
  40. int m=(l+r)>>;
  41. if(lazy[rt]==)
  42. {
  43. value[rt<<]=m-l+;
  44. value[rt<<|]=r-m;
  45. lazy[rt<<]=lazy[rt<<|]=;
  46. }
  47. else if(lazy[rt]==)
  48. {
  49. value[rt<<]=value[rt<<|]=;
  50. lazy[rt<<]=lazy[rt<<|]=;
  51. }
  52. else if(lazy[rt]==)
  53. {
  54. value[rt<<]=m-l+-value[rt<<];
  55. value[rt<<|]=r-m-value[rt<<|];
  56. lazy[rt<<]=-lazy[rt<<];
  57. lazy[rt<<|]=-lazy[rt<<|];
  58. }
  59. lazy[rt]=;
  60. }
  61. void build(int l,int r,int rt)
  62. {
  63. value[rt]=,lazy[rt]=;
  64. if(l==r)return ;
  65. int m=(l+r)>>;
  66. build(ls);build(rs);
  67. }
  68. void update(int L,int R,int op,int l,int r,int rt)
  69. {
  70. if(L<=l&&r<=R)
  71. {
  72. if(op==)
  73. {
  74. value[rt]=r-l+;
  75. lazy[rt]=op;
  76. }
  77. else if(op==)
  78. {
  79. value[rt]=;
  80. lazy[rt]=op;
  81. }
  82. else
  83. {
  84. if(lazy[rt])pushdown(l,r,rt);
  85. value[rt]=r-l+-value[rt];
  86. lazy[rt]=op;
  87. }
  88. return ;
  89. }
  90. pushdown(l,r,rt);
  91. int m=(l+r)>>;
  92. if(L<=m)update(L,R,op,ls);
  93. if(m<R)update(L,R,op,rs);
  94. pushup(rt);
  95. }
  96. int query(int l,int r,int rt)
  97. {
  98. if(l==r)return l;
  99. pushdown(l,r,rt);
  100. int m=(l+r)>>;
  101. if(value[rt<<]==m-l+)return query(rs);
  102. else return query(ls);
  103. }
  104. void add(ll x)
  105. {
  106. if(x!=)Hash[cnt++]=x;
  107. }
  108. int main()
  109. {
  110. int n;
  111. cnt=;
  112. scanf("%d",&n);
  113. for(int i=;i<n;i++)
  114. {
  115. scanf("%d%lld%lld",&q[i].t,&q[i].l,&q[i].r);
  116. add(q[i].l-),add(q[i].l),add(q[i].l+);
  117. add(q[i].r-),add(q[i].r),add(q[i].r+);
  118. }
  119. Hash[cnt++]=;
  120. sort(Hash,Hash+cnt);
  121. cnt=unique(Hash,Hash+cnt)-Hash;
  122. // for(int i=0;i<cnt;i++)printf("%lld ",Hash[i]);
  123. // puts("");
  124. build(,cnt,);
  125. for(int i=;i<n;i++)
  126. {
  127. int op=q[i].t;
  128. int tel=lower_bound(Hash,Hash+cnt,q[i].l)-Hash;
  129. int ter=lower_bound(Hash,Hash+cnt,q[i].r)-Hash;
  130. update(tel+,ter+,q[i].t,,cnt,);
  131. int ans=query(,cnt,);
  132. // printf("%d %d %d\n",tel,ter,ans);
  133. printf("%lld\n",Hash[ans-]);
  134. }
  135. return ;
  136. }
  137. /********************
  138. 1
  139. 2 854690110384167294 954215012997404774
  140. ********************/

Educational Codeforces Round 23F的更多相关文章

  1. [Educational Codeforces Round 16]E. Generate a String

    [Educational Codeforces Round 16]E. Generate a String 试题描述 zscoder wants to generate an input file f ...

  2. [Educational Codeforces Round 16]D. Two Arithmetic Progressions

    [Educational Codeforces Round 16]D. Two Arithmetic Progressions 试题描述 You are given two arithmetic pr ...

  3. [Educational Codeforces Round 16]C. Magic Odd Square

    [Educational Codeforces Round 16]C. Magic Odd Square 试题描述 Find an n × n matrix with different number ...

  4. [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 ...

  5. [Educational Codeforces Round 16]A. King Moves

    [Educational Codeforces Round 16]A. King Moves 试题描述 The only king stands on the standard chess board ...

  6. Educational Codeforces Round 6 C. Pearls in a Row

    Educational Codeforces Round 6 C. Pearls in a Row 题意:一个3e5范围的序列:要你分成最多数量的子序列,其中子序列必须是只有两个数相同, 其余的数只能 ...

  7. Educational Codeforces Round 9

    Educational Codeforces Round 9 Longest Subsequence 题目描述:给出一个序列,从中抽出若干个数,使它们的公倍数小于等于\(m\),问最多能抽出多少个数, ...

  8. Educational Codeforces Round 37

    Educational Codeforces Round 37 这场有点炸,题目比较水,但只做了3题QAQ.还是实力不够啊! 写下题解算了--(写的比较粗糙,细节或者bug可以私聊2333) A. W ...

  9. 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 ...

随机推荐

  1. tpot从elastic search拉攻击数据之一 找本地数据端口

    前面,我们已经在ubuntu服务器上部署好了tpot,并启动进行数据捕获 可以通过64297端口登陆到kibana可视化平台查看捕获到攻击的情况. 现在要拉取攻击数据了,但是该怎么拉呢? 看了一上午的 ...

  2. > >> 将错误输出到文件

    将错误输出到文件 转载:https://blog.csdn.net/woshinia/article/details/18040063 1.覆盖写入: echo "日志内容"  & ...

  3. [luogu4556]雨天的尾巴

    [luogu4556]雨天的尾巴 luogu 发现是一顿子修改然后再询问,那么把修改树上差分一下再线段树合并 但是... 如果你只有35分... https://www.luogu.org/discu ...

  4. Linux网络调试工具资料链接

    Dropbox: https://huoding.com/2016/12/15/574 Tcpdump: http://roclinux.cn/?p=2474

  5. Andrew Ng机器学习编程作业:Support Vector Machines

    作业: machine-learning-ex6 1. 支持向量机(Support Vector Machines) 在这节,我们将使用支持向量机来处理二维数据.通过实验将会帮助我们获得一个直观感受S ...

  6. Submission Details [leetcode] 算法的改进

    最先看到这一题,直觉的解法就是len从1到s1.size()-1,递归调用比較s1和s2长度为len的子串是否相等.以及剩余部分是否相等. 将s1分成s1[len + rest],分别比較s2[len ...

  7. upsampling(上采样)& downsampled(降采样)

    缩小图像 缩小图像(或称为下采样(subsampled)或降采样(downsampled))的主要目的是两个: 使得图像符合显示区域的大小: 生成对应图像的缩略图: 下采样的原理: 对于一幅图像尺寸为 ...

  8. Springboot入门-日志框架配置(转载)

    默认情况下,Spring Boot会用Logback来记录日志,并用INFO级别输出到控制台. Logback是log4j框架的作者开发的新一代日志框架,它效率更高.能够适应诸多的运行环境,同时天然支 ...

  9. Grunt JS构建环境搭建以及使用入门

    Grunt JS构建环境搭建以及使用入门 1.应用场景 一种自动化任务处理工具,对于日常的需求(代码规则检查.代码合并)可以实现自动化执行,只需要保留package.json和Gruntfile.js ...

  10. Node.js API学习笔记(二)

    本文发表于本人博客. 上一节笔记说到创建Buffer实例,这节继续讲Buffer.本节讲解下Buffer的一些静态方法.写入以及读取方法. Buffer.isEncoding(编码)判断nodejs是 ...