写了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. Linux 虚拟机忘记root密码

    Linux 虚拟机忘记root密码可以按照下面的步骤重新设置密码: 1.在grub界面,也就是有press any key的那个界面,按下任意键 2.键入e,出现三行文字,按上下键选择kernel那一 ...

  2. CodeChef Chef and Churu [分块]

    题意: 单点修改$a$ 询问$a$的区间和$f$的区间和 原来普通计算机是这道题改编的吧... 对$f$分块,预处理$c[i][j]$为块i中$a_j$出现几次,$O(NH(N))$,只要每个块差分加 ...

  3. 面向对象编程总结--Python

    万物皆为对象.自然环境赋予人类无尽的遐想,而面向对象编程之思想就是来自于大自然.自然界,类和对象比比皆是,比如:鸟类和麻雀,鱼和鲤鱼......其中鸟类就是各种鸟的总称,而麻雀只不过是其中之一(对象) ...

  4. 文件读写io操作范例

    系统io读写,copy int main(int argc, char **argv) {  if(argc != 3) {   printf("Usage: %s <src> ...

  5. 初涉扫码登录:edusoho实现客户端扫码登录(简版)

    一.项目简介及需求 edusoho是一套商业版的在线教育平台,项目本身基于symfony2框架开发,现在有一款自己的APP,要求在不多修改edusoho自身代码的基础上,实现客户端对PC端扫码登录.不 ...

  6. TKCPP

    volume one: http://book.huihoo.com/thinking-in-cpp-2nd-ed-vol-one/ volume2 : http://book.huihoo.com/ ...

  7. Redmine基础: 邮件配置

    1.用文本编辑器打开 D:\Bitnami\redmine-2.6.5-0\apps\redmine\htdocs\config\configuration.yml 文件,找到以下内容: 2.配置邮件 ...

  8. Selenium+Python ---- 免登录、等待、unittest单元测试框架、PO模型

    1.免登录在进行测试的过程中难免会遇到登录的情况,给测试工作添加了工作量,本文仅提供一些思路供参考解决方式:手动请求中添加cookies.火狐的profile文件记录信息实现.人工介入.万能验证码.去 ...

  9. Python自动化--语言基础8--接口请求及封装

    基于http协议,最常用的是GET和POST两种方法. 接口文档需要包含哪些信息: 接口名称接口功能接口地址支持格式 json/xml请求方式请求示例请求参数(是否必填.数据类型.传递参数格式)返回参 ...

  10. 35 个 jQuery 小技巧

    1. 禁止右键点击 $(document).ready(function(){ $(document).bind("contextmenu",function(e){ return ...