[NOIP10.5模拟赛]1.a题解--离散化+异或线段树
题目链接:
咕咕咕
https://www.luogu.org/problemnew/show/CF817F
闲扯
在Yali经历几天折磨后信心摧残,T1数据结构裸题考场上连暴力都TM没打满
分析
观察到点值巨大,离散化即可
但是注意到\(1,l+1,r+1\)都是会产生答案的,也需要离散化,同时注意数组大小
然后区间异或线段树,为了查询我们记录一个数组\(sum0[now]\)表示now区间0的个数
同时相应的记录的一个\(sum1[now]\)表示区间1的个数方便各种操作的转换
下传标记时需要注意的就不多说了,也不用注意挺多,还挺好码的
但是注意数组别开小了!!!我们一条区间最多拓展四个点!
代码
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cctype>
#include <iostream>
#include <ext/pb_ds/hash_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#define ll long long
#define ri register int
using std::min;
using std::max;
using std::swap;
using namespace __gnu_pbds;
template <class T>inline void read(T &x){
x=0;int ne=0;char c;
while(!isdigit(c=getchar()))ne=c=='-';
x=c-48;
while(isdigit(c=getchar()))x=(x<<3)+(x<<1)+c-48;
x=ne?-x:x;return ;
}
const int maxn=400005;//数组一定要开大,线段树最多是平常的四倍
const int inf=0x7fffffff;
int L,R,dta;
int pos=-1;
struct Segment_Tree{
int sum1[maxn<<2],sum0[maxn<<2];
int tag[maxn<<2],set[maxn<<2];
inline void pushup(int now){
sum0[now]=sum0[now<<1]+sum0[now<<1|1];
sum1[now]=sum1[now<<1]+sum1[now<<1|1];
return ;
}
void build(int now,int l,int r){
set[now]=-1,tag[now]=0;
if(l==r){
sum0[now]=1,sum1[now]=0;
return ;
}
int mid=(l+r)>>1;
build(now<<1,l,mid);
build(now<<1|1,mid+1,r);
pushup(now);
}
inline void pushdown(int now,int ln,int rn){
if(tag[now]){
if(set[now]==-1){
if(set[now<<1]!=-1)set[now<<1]^=1;
if(set[now<<1|1]!=-1)set[now<<1|1]^=1;
//tag[now<<1]^=1,tag[now<<1|1]^=1;
swap(sum1[now<<1],sum0[now<<1]);
swap(sum1[now<<1|1],sum0[now<<1|1]);
}
tag[now]=0;
}
if(set[now]!=-1){
tag[now<<1]=tag[now<<1|1]=0;
set[now<<1]=set[now<<1|1]=set[now];
if(set[now]==1){
sum1[now<<1]=ln,sum0[now<<1]=0;
sum1[now<<1|1]=rn,sum0[now<<1|1]=0;
}
else{
sum1[now<<1]=0,sum0[now<<1]=rn;
sum1[now<<1|1]=0,sum0[now<<1|1]=rn;
}
set[now]=-1;
}
return ;
}
void update_s1(int now,int l,int r){
if(L<=l&&r<=R){
set[now]=1;
tag[now]=0;
sum0[now]=0,sum1[now]=(r-l+1);
return ;
}
int mid=(l+r)>>1;
pushdown(now,mid-l+1,r-mid);
if(L<=mid)update_s1(now<<1,l,mid);
if(mid<R)update_s1(now<<1|1,mid+1,r);
pushup(now);
}
void update_s0(int now,int l,int r){
if(L<=l&&r<=R){
set[now]=0;
tag[now]=0;
sum0[now]=(r-l+1),sum1[now]=0;
return ;
}
int mid=(l+r)>>1;
pushdown(now,mid-l+1,r-mid);
if(L<=mid)update_s0(now<<1,l,mid);
if(mid<R)update_s0(now<<1|1,mid+1,r);
pushup(now);
return ;
}
void update_xor(int now,int l,int r){
if(L<=l&&r<=R){
if(set[now]!=-1){
set[now]^=1;
}
else tag[now]^=1;
swap(sum0[now],sum1[now]);
return ;
}
int mid=(l+r)>>1;
pushdown(now,mid-l+1,r-mid);
if(L<=mid)update_xor(now<<1,l,mid);
if(mid<R)update_xor(now<<1|1,mid+1,r);
pushup(now);
return ;
}
void query(int now,int l,int r){
if(sum0[now]==0)return ;
if(l==r){
pos=l;
return ;
}
int mid=(l+r)>>1;
pushdown(now,mid-l+1,r-mid);
if(sum0[now<<1]!=0)query(now<<1,l,mid);
if(pos!=-1)return;
if(sum0[now<<1|1]!=0)query(now<<1|1,mid+1,r);
pushup(now);
return ;
}
}T;
struct OP{
int ty;ll l,r;
}op[maxn];
int n;
ll f[maxn<<2];int tot=0;
gp_hash_table <ll,int> h;
int main(){
freopen("a.in","r",stdin);
freopen("a.out","w",stdout);
read(n);
f[++tot]=1;
for(ri i=1;i<=n;i++){
read(op[i].ty),read(op[i].l),read(op[i].r);
f[++tot]=op[i].l,f[++tot]=op[i].r;
f[++tot]=op[i].l+1;
f[++tot]=op[i].r+1;
}
std::sort(f+1,f+1+tot);
tot=std::unique(f+1,f+1+tot)-(f+1);
for(ri i=1;i<=tot;i++){
h[f[i]]=i;
}
T.build(1,1,tot);
//tot=1000;
for(ri i=1;i<=n;i++){
L=h[op[i].l],R=h[op[i].r];
//L=op[i].l,R=op[i].r;
//printf("%d %d\n",L,R);
if(op[i].ty==1){
T.update_s1(1,1,tot);
}
if(op[i].ty==2){
T.update_s0(1,1,tot);
}
if(op[i].ty==3){
T.update_xor(1,1,tot);
}
pos=-1;
T.query(1,1,tot);
//printf("--%d--\n",pos);
printf("%lld\n",f[pos]);
}
return 0;
}
[NOIP10.5模拟赛]1.a题解--离散化+异或线段树的更多相关文章
- [NOIP10.6模拟赛]2.equation题解--DFS序+线段树
题目链接: 咕 闲扯: 终于在集训中敲出正解(虽然与正解不完全相同),开心QAQ 首先比较巧,这题是\(Ebola\)出的一场模拟赛的一道题的树上强化版,当时还口胡出了那题的题解 然而考场上只得了86 ...
- [NOIP10.4模拟赛]3.z题解--思维
题目链接: 咕咕 闲扯: 哈哈这道T3考场上又敲了5个namespace,300+行,有了前车之鉴还对拍过,本以为子任务分稳了 结果只有30分哈哈,明明用极限数据对拍过不知怎么回事最后数据又是读不全, ...
- [NOIP10.3模拟赛]3.w题解--神奇树形DP
题目链接: 咕 闲扯: 这题考场上把子任务都敲满了,5个namespace,400行11k 结果爆0了哈哈,因为写了个假快读只能读入一位数,所以手测数据都过了,交上去全TLE了 把边分成三类:0. 需 ...
- [NOIP10.6模拟赛]1.merchant题解--思维+二分
题目链接: while(1)gugu(while(1)) 闲扯 考场上怕T2正解写挂其他两题没管只打了暴力,晚上发现这题思维挺妙的 同时想吐槽出题人似乎热衷卡常...我的巨大常数现在显露无疑QAQ 分 ...
- [NOIP10.5模拟赛]3.c题解--思维
题目链接 这次不咕了 https://www.luogu.org/problemnew/show/AT2389 闲扯 考场20分爆搜走人 \cy 话说这几天T3都很考验思维啊 分析 我们先钦定一只鸡( ...
- [NOIP10.4模拟赛]2.y题解--折半搜索+状压计数
题目链接: 咕 闲扯: 这题暴力分似乎挺多,但是一些奇奇怪怪的细节没注意RE了,还是太菜了 分析: 首先我们考虑最naiive的状压DP ,\(f[u][v][state]\)表示u开头,v结尾是否存 ...
- 计蒜客模拟赛 #5 (B 题) 动态点分治+线段树
虽然是裸的换根dp,但是为了在联赛前锻炼码力,强行上了点分树+线段树. 写完+调完总共花了不到 $50$ 分钟,感觉还行. code: #include <bits/stdc++.h> # ...
- R - Weak Pair HDU - 5877 离散化+权值线段树+dfs序 区间种类数
R - Weak Pair HDU - 5877 离散化+权值线段树 这个题目的初步想法,首先用dfs序建一颗树,然后判断对于每一个节点进行遍历,判断他的子节点和他相乘是不是小于等于k, 这么暴力的算 ...
- 2018 ACMICPC上海大都会赛重现赛 H - A Simple Problem with Integers (线段树,循环节)
2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 H - A Simple Problem with Integers (线段树,循环节) 链接:https://ac.nowcoder.co ...
随机推荐
- 查看memcache版本
window: cmd中用telnet 127.0.0.1 11211这样的命令连接上memcache,然后直接输入stats就可以得到memcache服务器的版本. 注意:memcache的默认端口 ...
- databinding 填坑 绑定动作是延后生效
binding = FragmentNewsMainLayout750Binding.inflate(inflater); homePageViewModel = new HomePageViewMo ...
- Mac os 安装 alipay-sdk-python 3.3.92错误 line 278,其实是另一个依赖包pycrypto安装有问题。
日期2019.7.17解决的问题. 系统mac os 10.14.5 python 3.6 django 1.11 要安装alipay-sdk-python 3.3.92错误 line 278, in ...
- Windows Qt 项目中文乱码
在头文件中加入 #if _MSC_VER >= 1600 #pragma execution_character_set("utf-8") #endif
- django.template.exceptions.TemplateDoesNotExist: index.html
django.template.exceptions.TemplateDoesNotExist: index.html 在网上查了下,setting中 TEMPLATES 的 'DIRS' 需要添加o ...
- 推荐一个加载动图的网站loading.io
推荐一个非常好玩的loading gif的资源网站:https://loading.io/ 里面有各种loading的动图.
- Spring Aop(一)——Aop简介
转发地址:https://www.iteye.com/blog/elim-2394629 1 Aop简介 AOP的全称是Aspect Oriented Programming,翻译成中文是面向切面编程 ...
- swift 第十四课 可视化view: @IBDesignable 、@IBInspectable
以前应objctiew-c 写项目的时候,就知道有这两个关键字,现在用swift了.用法稍作改变,基本用法还是一致的 虽然使用这个之后,有时候会报错的非常的莫名其妙----(其实还是自己技术不够牛…… ...
- web框架初阶
第一站 文件结构:web--- |--home.py #页面处理函数 |--index.py #主体函数 |--indexPlus.py #主体函数加强版 |--webdaem.py #通过we ...
- [System.Serializable],
[System.Serializable]添加在类,枚举,结构前面,可以让该这些对象在inspector中显示 [SerializeField]是设置非public 成员对象在inspector中显示