CF Educational Round 23 F.MEX Queries
写了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的更多相关文章
- 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 ...
- CF Educational Round 78 (Div2)题解报告A~E
CF Educational Round 78 (Div2)题解报告A~E A:Two Rival Students 依题意模拟即可 #include<bits/stdc++.h> us ...
- Codeforces Educational Round 23
A emmmmmmmmm B emmmmmmmmm C(套路) 题意: 给定n和s(n,s<=1e18),计算n以内有多少个数x满足(x-x的各个位置数字之和)>=s 分析: 容易想到如果 ...
- Educational Codeforces Round 23 A-F 补题
A Treasure Hunt 注意负数和0的特殊处理.. 水题.. 然而又被Hack了 吗的智障 #include<bits/stdc++.h> using namespace std; ...
- [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 ...
- Educational Codeforces Round 40 F. Runner's Problem
Educational Codeforces Round 40 F. Runner's Problem 题意: 给一个$ 3 * m \(的矩阵,问从\)(2,1)$ 出发 走到 \((2,m)\) ...
- [Educational Round 5][Codeforces 616F. Expensive Strings]
这题调得我心疲力竭...Educational Round 5就过一段时间再发了_(:з」∠)_ 先后找了三份AC代码对拍,结果有两份都会在某些数据上出点问题...这场的数据有点水啊_(:з」∠)_[ ...
- [Educational Round 3][Codeforces 609E. Minimum spanning tree for each edge]
这题本来是想放在educational round 3的题解里的,但觉得很有意思就单独拿出来写了 题目链接:609E - Minimum spanning tree for each edge 题目大 ...
- Codeforces Educational Round 33 题解
题目链接 Codeforces Educational Round 33 Problem A 按照题目模拟,中间发现不对就直接输出NO. #include <bits/stdc++.h> ...
随机推荐
- 洛谷 [P3398] 仓鼠找sugar
树剖求LCA 我们可以发现,两条路径ab,cd相交,当且仅当 dep[lca(a,b)]>=dep[lca(c,d)]&(lca(lca(a,b),c)==lca(a,b)||lca(l ...
- BZOJ 2809: [Apio2012]dispatching [主席树 DFS序]
传送门 题意:查询树上根节点值*子树中权值和$\le m$的最大数量 最大值是多少 求$DFS$序,然后变成区间中和$\le m$最多有几个元素,建主席树,然后权值线段树上二分就行了 $WA$:又把边 ...
- [LeetCode] 679. 24 Game(回溯法)
传送门 Description You have 4 cards each containing a number from 1 to 9. You need to judge whether the ...
- Git教程:
使用前配置: git init git config --global user.name "yanpeng1314" git config --global user.email ...
- ionic2+Angular 依赖注入之Subject ——使用Subject来实现组件之间的通信
在Angular+ionic2 开发过程中,我们不难发现,页面之间跳转之后返回时是不会刷新数据的. 场景一:当前页面需要登录之后才能获取数据--去登录,登录成功之后返回--页面需要手动刷新才能获取到数 ...
- [Python Study Notes]实现对键盘控制与监控
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ...
- MySQL统计函数记录——按月、按季度、按日、时间段统计
按年汇总,统计:select sum(mymoney) as totalmoney, count(*) as sheets from mytable group by date_format(col, ...
- Filezilla Server 出现Error, could not connect to server解决办法
打开任务管理器:Win+R:services.msc找到Filezilla Server并启动服务
- [翻译] 编写高性能 .NET 代码--第二章 GC -- 减少大对象堆的碎片,在某些情况下强制执行完整GC,按需压缩大对象堆,在GC前收到消息通知,使用弱引用缓存对象
减少大对象堆的碎片 如果不能完全避免大对象堆的分配,则要尽量避免碎片化. 对于LOH不小心就会有无限增长,但LOH使用的空闲列表机制可以减轻增长的影响.利用这个空闲列表,我们可以在两块分配区域中间找到 ...
- ch11 持有对象
Java集合的基本类型:List.Set.Queue.Map 使用容器时若未指定泛型参数ArrayList apples=new ArrayList();,则容器中所有元素都为Object类型,使用时 ...