写了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. SpringMVC源码情操陶冶-DispatcherServlet

    本文对springmvc核心类DispatcherServlet作下简单的向导,方便博主与读者查阅 DispatcherServlet-继承关系 分析DispatcherServlet的继承关系以及主 ...

  2. Hadoop学习笔记四

    一.fsimage,edits和datanode的block在本地文件系统中位置的配置 fsimage:hdfs-site.xml中的dfs.namenode.name.dir  值例如file:// ...

  3. BZOJ 3622: 已经没有什么好害怕的了 [容斥原理 DP]

    3622: 已经没有什么好害怕的了 题意:和我签订契约,成为魔法少女吧 真·题意:零食魔女夏洛特的结界里有糖果a和药片b各n个,两两配对,a>b的配对比b>a的配对多k个学姐就可能获胜,求 ...

  4. 编写服务器程序时遇到的connect:no route to host的问题

    亲测,,ftp服务器:在一台虚拟机上,没有问题.但是在不同的计算机或虚拟机上就会出现这种错误提示.一般是linux防火墙的问题 解决方法: 关闭linux防火墙 在root账户下 命令行:servic ...

  5. jira + confluence 安装和破解

    Window环境: 环境准备 安装JAVA1.8以上版本 安装SQL SERVER 或 MySQL: jira安装和破解 下载安装包 https://downloads.atlassian.com/s ...

  6. java中的@Override标签

    @Override标签的作用: @Override是伪代码,表示方法重写. @Override标签的好处: 1.作为注释,帮助自己检查是否正确的复写了父类中已有的方法 2.便于别人理解代码 3.编译器 ...

  7. Vue的土著指令和自定义指令

    1.土著指令 当我开始学习Vue的时候,看官网的时候看到了"指令"两个字.我愣住了,what?指令是啥啊?后来继续往下看,像这种什么"v-for""v ...

  8. 【Oracle】-初识PL/SQL

    在最近的工作中要用到存储过程和函数,索性把PL/SQL整体的看一下.之前看过基本书和园子里的博文,在这里将所学简单总结. 一.基本语句 1.大小写 2.分隔符  --  : 3.引用字符串  --   ...

  9. AnnotationUtils

    /** * 查询类中符合指定annotation的属性信息 * @param objCls 实体类 * @param annCls 注解类 * @return HashMap<实体属性名, An ...

  10. LNMP环境下搭建wordpress

    WordPress 下载WordPress安装包,可以直接wget获取也可以ftp上传,解压到/usr/share/nginx/html/blog-wp,访问index.php即进行安装:   wor ...