写了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;
}

CF Educational Round 23 F.MEX Queries的更多相关文章

  1. Educational Codeforces Round 23 F. MEX Queries 离散化+线段树

    F. MEX Queries time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...

  2. CF Educational Round 78 (Div2)题解报告A~E

    CF Educational Round 78 (Div2)题解报告A~E A:Two Rival Students​ 依题意模拟即可 #include<bits/stdc++.h> us ...

  3. Codeforces Educational Round 23

    A emmmmmmmmm B emmmmmmmmm C(套路) 题意: 给定n和s(n,s<=1e18),计算n以内有多少个数x满足(x-x的各个位置数字之和)>=s 分析: 容易想到如果 ...

  4. Educational Codeforces Round 23 A-F 补题

    A Treasure Hunt 注意负数和0的特殊处理.. 水题.. 然而又被Hack了 吗的智障 #include<bits/stdc++.h> using namespace std; ...

  5. [cf contest 893(edu round 33)] F - Subtree Minimum Query

    [cf contest 893(edu round 33)] F - Subtree Minimum Query time limit per test 6 seconds memory limit ...

  6. Educational Codeforces Round 40 F. Runner's Problem

    Educational Codeforces Round 40 F. Runner's Problem 题意: 给一个$ 3 * m \(的矩阵,问从\)(2,1)$ 出发 走到 \((2,m)\) ...

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

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

  8. [Educational Round 3][Codeforces 609E. Minimum spanning tree for each edge]

    这题本来是想放在educational round 3的题解里的,但觉得很有意思就单独拿出来写了 题目链接:609E - Minimum spanning tree for each edge 题目大 ...

  9. Codeforces Educational Round 33 题解

    题目链接   Codeforces Educational Round 33 Problem A 按照题目模拟,中间发现不对就直接输出NO. #include <bits/stdc++.h> ...

随机推荐

  1. BZOJ 3239: Discrete Logging [BGSG]

    裸题 求\(ind_{n,a}b\),也就是\(a^x \equiv b \pmod n\) 注意这里开根不能直接下取整 这个题少了一些特判也可以过... #include <iostream& ...

  2. win10安装elementary os双系统

    elementary os是ubuntu的一个分支,界面有点像苹果,比较漂亮.如图: 从已有的磁盘中划出一块空白分区,将elementary单独安装在这个分区里,这个分区需要比其他分区的剩余空间都要大 ...

  3. 小甲鱼OD学习第11讲

    这次我们的任务是破解这个需要注册的软件,如下图所示 我们这次从字符串入手,我们查找 unregistered  字符串 然后我们在如下图的字符串下断点 然后我们来到断点处,我们观察到 地址为 0040 ...

  4. 一、scrapy的下载安装---Windows(安装软件太让我伤心了)

    写博客就和笔记一样真的很有用,你可以随时的翻阅.爬虫的爬虫原理与数据抓取.非结构化与结构化数据提取.动态HTML处理和简单的图像识别已经学完,就差整理博客了 开始学习scrapy了,所以重新建了个分类 ...

  5. snowflake 分布式唯一ID生成器

    本文来自我的github pages博客http://galengao.github.io/ 即www.gaohuirong.cn 摘要: 原文参考运维生存和开源中国上的代码整理 我的环境是pytho ...

  6. Mybatis 动态使用update语句

    update pf_product_audio_t <trim prefix="set" suffixOverrides=","> <if t ...

  7. 使用mybatis插入自增主键ID的数据后返回自增的ID

    在开发中碰到用户注册的功能需要用到用户ID,但是用户ID是数据库自增生成的,这种情况上网查询后使用下面的方式配置mybatis的insert语句可以解决: <insert id="in ...

  8. 读《Linux Shell脚本攻略》(第2版) 总结

    前段时间读完了<Linux Shell脚本攻略>(第2版)这本书,给部分想读这本书的人分享下个人感受. 说下这本书的难度吧.纯新手或者只懂少部分编程知识的人,读起来还是有很大难度的.以我为 ...

  9. SmileyFace——基于OpenCV的人脸人眼检测、面部识别程序

    项目地址 https://github.com/guoyaohua/SmileyFace 开发环境 Visual Studio 2010 MFC + OpenCV 功能描述 静态图像人脸检测 视频人脸 ...

  10. HDU - 3567 Eight II (bfs预处理 + 康托) [kuangbin带你飞]专题二

    类似HDU1430,不过本题需要枚举X的九个位置,分别保存状态,因为要保证最少步数.要保证字典序最小的话,在扩展节点时,方向顺序为:down, left, right, up. 我用c++提交1500 ...