写了3小时 = =。这两天堕落了,昨天也刷了一晚上hihocoder比赛,还爆了零。之后得节制点了,好好准备考研。。

首先很容易想到 压缩数据 + 线段树
然后对于Pushdown真很难写。。需要牵涉到状态修改(所以我又写了一个adjust函数,辅助修改)
我一直跪在test7,因为3号修改在一开始就会出现cover符号的修改,我一开始没有加(比方说1-4都是0,现在 做3 1 4,直接吧1-4的状态改为1就行了)

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <algorithm>
#include <iostream>
#include <map>
#include <set>
#include <queue>
#include <cmath>
using namespace std;
typedef long long ll;
#define lson l,m, rt<<1
#define rson m+1, r, rt<<1|1
const int N = 2e5+5;
const int INF = 0x3f3f3f3f;int a[N]; ll b[N], c[N];
ll has[N << 1];
map<ll, int> mp;int sum[N << 2];
int cover[N << 2];void adjust(int rt) {if(cover[rt] == 0) cover[rt] = -2;else if(cover[rt] == -2) cover[rt] = 0;else cover[rt] *= -1;
} void Pushdown(int rt, int len) {if(cover[rt] != 0) {if(cover[rt] == 1) {cover[rt << 1] = cover[rt << 1|1] = cover[rt];sum[rt << 1] = (len+1) / 2;sum[rt << 1|1] = len / 2;}else if(cover[rt] == -1) {cover[rt << 1] = cover[rt << 1|1] = cover[rt];sum[rt << 1] = 0;sum[rt << 1|1] = 0;}else {sum[rt << 1] = (len+1) / 2 - sum[rt << 1];sum[rt << 1|1] = len / 2 - sum[rt << 1|1];adjust(rt << 1); adjust(rt << 1|1); }cover[rt] = 0;}
}void Add(int L, int R, int l, int r, int rt) {if(sum[rt] == r-l+1) return;if(L <= l && r <= R) {sum[rt] = r-l+1;cover[rt] = 1;return ;}int m = (l + r) >> 1;Pushdown(rt, r-l+1);if(L <= m) Add(L, R, lson); if(R > m)  Add(L, R, rson);sum[rt] = sum[rt << 1] + sum[rt << 1|1];
}
void Delete(int L, int R, int l, int r, int rt) {if(sum[rt] == 0) return;if(L <= l && r <= R) {sum[rt] = 0;cover[rt] = -1;return;}int m = (l + r) >> 1;Pushdown(rt, r-l+1);if(L <= m) Delete(L, R, lson); if(R > m)  Delete(L, R, rson);sum[rt] = sum[rt << 1] + sum[rt << 1|1];
}
void Invert(int L, int R, int l, int r, int rt) {if(L <= l && r <= R) {adjust(rt);sum[rt] = (r-l+1) - sum[rt];return;}int m = (l + r) >>1;Pushdown(rt, r-l+1);if(L <= m) Invert(L, R, lson);if(R > m) Invert(L, R, rson);sum[rt] = sum[rt << 1] + sum[rt << 1|1];
}
int suc = 0;
void Find(int l, int r, int rt) {if(suc) return;if(sum[rt] == r-l+1) return;else if(sum[rt] == 0) {printf("%lld\n", has[l-1]); suc = 1; return;}Pushdown(rt, r-l+1);int m = (l + r) >>1;Find(lson); Find(rson);
}int main() {int q;while(~scanf("%d", &q)) {mp.clear();memset(sum, 0, sizeof(sum));memset(cover, 0, sizeof(cover));int tot = 0;has[tot ++] = 1;for(int i = 0; i < q; ++i) {scanf("%d %lld %lld", &a[i], &b[i], &c[i]);has[tot ++ ] = b[i]; has[tot ++ ] = c[i]+1; }   sort(has, has + tot);tot = unique(has, has + tot) - has;for(int i = 0; i < tot; ++i) {mp[has[i]] = i+1;//  printf("%lld ", has[i]);}for(int i = 0; i < q; ++i) {if(a[i] == 1) {Add(mp[b[i]], mp[c[i]+1]-1, 1, tot, 1);}else if(a[i] == 2) {Delete(mp[b[i]], mp[c[i]+1]-1, 1, tot, 1);}else Invert(mp[b[i]], mp[c[i]+1]-1, 1, tot, 1);suc = 0; Find(1, tot, 1);}}return 0;
}

转载于:https://www.cnblogs.com/Basasuya/p/8433698.html

CF Educational Round 23 F.MEX Queries相关推荐

  1. CF Educational Round 57(1096) 比赛记录

    这里是链接 本来想带学弟飞的,结果自己先gg了... 外校高一大佬太强了orz,在我前面溜的飞起,还切了 F 哎,差一点就可以上紫名的,现在寄希望于 Good Bye 2018 了qwq 老年选手的手 ...

  2. Codeforces Educational Round#21 F(808F) Solution:网络流(最小割)

    题意:给出一组卡牌(100张),卡牌有三个属性值:power,c,level,其中c和level是用来限制的,power是目标值. 具体的限制规则是:只有level小于等于玩家的playerlevel ...

  3. Educational Codeforces Round 25 G. Tree Queries

    题目链接:Educational Codeforces Round 25 G. Tree Queries 题意: 给你一棵树,一开始所有的点全是黑色,有两种操作. 1 x 将x这个点变为黑色,保证第一 ...

  4. Codeforces Round #675 (Div. 2) F. Boring Queries 区间lcm + 主席树

    传送门 文章目录 题意: 思路: 题意: 给你一个长度为nnn的序列aaa,qqq个询问,每次询问[l,r][l,r][l,r]内的lcmlcmlcm是多少,对1e9+71e9+71e9+7取模. n ...

  5. Educational Codeforces Round 23:E. Choosing The Commander(字典树01异或)

    Educational Codeforces Round 23:E. Choosing The Commander(字典树01异或) 题意: 3种操作: 1 插入一个数 2 删除一个数 3 给出一个数 ...

  6. [CF]Codeforces Round #529 (Div. 3)

    [CF]Codeforces Round #529 (Div. 3) C. Powers Of Two Description A positive integer xx is called a po ...

  7. 20.CF817F MEX Queries 线段树(Lazy标记练习)

    20.CF817F MEX Queries 离散化+区间覆盖+区间反转线段树 个人Limitの线段树题单题解主目录:Limitの线段树题单 题解目录_HeartFireY的博客-CSDN博客 要求维护 ...

  8. [Educational Round 5][Codeforces 616F. Expensive Strings]

    这题调得我心疲力竭...Educational Round 5就过一段时间再发了_(:з」∠)_ 先后找了三份AC代码对拍,结果有两份都会在某些数据上出点问题...这场的数据有点水啊_(:з」∠)_[ ...

  9. Codeforces Educational Round 5

    Codeforces Educational Round 5 通过数: 4 Standing: 196/4176 题目链接: http://codeforces.com/contest/616 A: ...

最新文章

  1. bat kafka启动_windows 搭建kafka、zookeeper环境
  2. docker虚拟机动态扩展内存
  3. phpstudy搭建网站使用php,教你用phpstudy搭建本地服务并建dedecms网站
  4. pandas高效读取大文件(csv)方法之-parquet
  5. 大数据学习(1)Hadoop安装
  6. 【洛谷】P2179 [NOI2012]骑行川藏
  7. ThinkPHP5有关模型hasOne、hasMany、belongsTo详解
  8. “睡服”面试官系列第十九篇之async函数(建议收藏学习)
  9. 【牛客 - 330G】Applese 的毒气炸弹(最小生成树,构造,判连通图)
  10. GDKOI2018发烧记
  11. Leetcode每日一题:42.trapping-rain-water(接雨水)
  12. windows7局域网传输到mac_计算机三级网络技术(5):局域网技术基础及应用
  13. IP子网划分【网工复习专题】2022.5.8
  14. paddle——站在巨人肩膀上及背刺二三事
  15. 2015-点餐系统(服务器)
  16. Ubuntu 18.04 修改中国时区
  17. 计算机一级wps必背知识点,计算机一级WPSoffice考前复习题
  18. 卸载 Mac 默认的 Xcode 附带的 git
  19. PHP设计模式-适配器模式
  20. Python基础(十二)——循环语句

热门文章

  1. 【LeetCode】70.爬楼梯
  2. linux mint 17.3 内核,LinuxMint 17.3 Cinnamon抢鲜评测
  3. 3310复刻版 java_终于等到你:诺基亚3310复刻版开箱简评
  4. java web 总结,Java Web 相关概念经典总结(一)
  5. illegalargumentexception是什么异常_线程出现异常!应该如何处理?
  6. C++知识点43——解引用运算符和箭头运算符的重载及智能指针类的实现
  7. jsp弹窗修改信息_WEB最最最初级修改用户信息
  8. springframework引入不进来_啥?你不知道JWT
  9. js---PC端滑动进度条
  10. openlayers 根据style设置显示级别并在字体加背景框