写了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. ES6与canvas实现鼠标小球跟随效果

    最近闲来无聊,看了下ES6的语法,结合canvas实现了动画特效--随着鼠标的移动,会有小球跟随且自动消失的动画. 首先,html部分,目前就一个canvas标签. <canvas id=&qu ...

  2. MOBA服务器开发第一阶段完成总结

    开发历程 项目是从8月20日左右开始开发的,到今天一个月不到吧. 除了底层库和服务器架构外我们大致开发了5个服务器为: 一 ) . 战斗服务器 二 ) . 匹配服务器 三 ) . 验证服务器 四 ) ...

  3. 【WC2013】糖果公园 [树上莫队]

    题意: 一棵树,修改一个点的颜色,询问两点路径上每种颜色的权值$val[c]$*出现次数的权值$cou[w[c]]$的和 sro VFK 树上莫队 按照王室联邦的方法分块,块的大小直径个数有保证,并不 ...

  4. SDP(5):ScalikeJDBC- JDBC-Engine:Streaming

    作为一种通用的数据库编程引擎,用Streaming来应对海量数据的处理是必备功能.同样,我们还是通过一种Context传递产生流的要求.因为StreamingContext比较简单,而且还涉及到数据抽 ...

  5. 使用VS Code开发asp.net core (下)

    第一部分: https://www.cnblogs.com/cgzl/p/8450179.html 本文是基于Windows10的. Debugging javascript 打开wwwroot/js ...

  6. 聊聊一直困扰前端程序员的浏览器兼容-【css】

    1.为什么会出现浏览器兼容问题? 由于各大主流浏览器由不同的厂家开发,所用的核心架构和代码也很难重和,这就为各种莫名其妙的Bug(代码错误)提供了温床.再加上各大厂商出于自身利益考虑而设置的种种技术壁 ...

  7. HashMap----工作原理

    先来些简单的问题 "你用过HashMap吗?" "什么是HashMap?你为什么用到它?" 几乎每个人都会回答"是的",然后回答HashMa ...

  8. 打开word时出现the setup controller has encountered a problem during install解决办法

    问题电脑为win7,office是默认安装 删除下面文件夹即可解决该问题 C:\Program Files\Common Files\Microsoft Shared\OFFICE12\Office ...

  9. 案例分析——BAT业务https化经历

         一.前言      通常的http访问会遭到中间人攻击.网络嗅探等普通用户感知不到的恶意行为,这些行为会篡改用户浏览页面引导用户访问非法网站.抓取用户的上网行为以及个人信息.严重的会造成用户 ...

  10. Pycharm常用的使用方法

    PyCharm是一种Python IDE,带有一整套可以帮助用户在使用Python语言开发时提高其效率的工具,比如调试.语法高亮.Project管理.代码跳转.智能提示.自动完成.单元测试.版本控制. ...