CF2143F Increasing Xor

news/2025/9/19 22:36:29/文章来源:https://www.cnblogs.com/dcytrl/p/19101812

我咋天天忘。还怎么学 OI 啊。

题意

给定长度为 \(n\) 的序列 \(a\)\(q\) 次询问给定 \(l,r\),每次查询提取出 \([l,r]\) 这段子区间,在这段子区间中你能执行任意次操作,每次操作任选 \(l\le i\le j\le r\) 然后 \(a_j\leftarrow a_i\oplus a_j\)。求是否存在一种方案使得 \(a_{l,\cdots,r}\) 严格递增。

\(\sum n,\sum q\le 2\times10^5,1\le a_i<2^{20}\)

分析

如果是全局查询,那么首先对每个位置 \(i\) 建出前 \(i\) 个元素的线性基,然后按照线性基有效元素个数分类分出 \(O(\log V)\) 类,每一类的线性基相同。对于每一类,假设前一类的最大值为 \(x\),这一类要填的长度为 \(len\),那么如果在这一类的线性基中 \(x\) 排名为 \(rk\),那么在这一类中我们就选取排名为 \(rk+1\)\(rk+len\) 之间的数,该类的末尾显然就是排名 \(rk+len\) 的数。而求线性基第 \(k\) 大和一个数 \(x\) 的排名都是基本操作,单次复杂度一个 log。

现在考虑区间查询,考虑前缀线性基,即每次插入一个数时保留时间戳靠后的数,然后将时间戳靠前的数往后插入。由于需要求有效元素个数,扫描线 \(l\) 删除出现时刻 \(<l\) 的数即可。总时间复杂度 \(O(n\log^2n)\)

点击查看代码
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
#include<map>
#include<unordered_map>
#include<vector>
#include<queue>
#include<stack>
#include<bitset>
#include<set>
#include<array>
#include<tuple>
#include<ctime>
#include<random>
#include<cassert>
#include<chrono>
#define x1 xx1
#define y1 yy1
#define IOS ios::sync_with_stdio(false)
#define ITIE cin.tie(0)
#define OTIE cout.tie(0)
#define PY puts("Yes")
#define PN puts("No")
#define PW puts("-1")
#define P0 puts("0")
#define P__ puts("")
#define PU puts("--------------------")
#define mp make_pair
#define fi first
#define se second
#define gc getchar
#define pc putchar
#define pb emplace_back
#define un using namespace
#define il inline
#define all(x) x.begin(),x.end()
#define mem(x,y) memset(x,y,sizeof x)
#define popc __builtin_popcountll
#define rep(a,b,c) for(int a=(b);a<=(c);++a)
#define per(a,b,c) for(int a=(b);a>=(c);--a)
#define reprange(a,b,c,d) for(int a=(b);a<=(c);a+=(d))
#define perrange(a,b,c,d) for(int a=(b);a>=(c);a-=(d))
#define graph(i,j,k,l) for(int i=k[j];i;i=l[i].nxt)
#define lowbit(x) ((x)&-(x))
#define lson(x) ((x)<<1)
#define rson(x) ((x)<<1|1)
//#define double long double
//#define int long long
//#define int __int128
using namespace std;
using i64=long long;
using u64=unsigned long long;
using pii=pair<int,int>;
template<typename T1,typename T2>inline bool ckmx(T1 &x,T2 y){return x>=y?0:(x=y,1);}
template<typename T1,typename T2>inline bool ckmn(T1 &x,T2 y){return x<=y?0:(x=y,1);}
inline auto rd(){int qwqx=0,qwqf=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')qwqf=-1;ch=getchar();}while(ch>='0'&&ch<='9'){qwqx=(qwqx<<1)+(qwqx<<3)+ch-48;ch=getchar();}return qwqx*qwqf;
}
template<typename T>inline void write(T qwqx,char ch='\n'){if(qwqx<0){qwqx=-qwqx;putchar('-');}int qwqy=0;static char qwqz[40];while(qwqx||!qwqy){qwqz[qwqy++]=qwqx%10+48;qwqx/=10;}while(qwqy--){putchar(qwqz[qwqy]);}if(ch)putchar(ch);
}
bool Mbg;
const int mod=998244353;
template<typename T1,typename T2>inline void adder(T1 &x,T2 y){x+=y,x=x>=mod?x-mod:x;}
template<typename T1,typename T2>inline void suber(T1 &x,T2 y){x-=y,x=x<0?x+mod:x;}
const int maxn=2e5+5,inf=0x3f3f3f3f;
const long long llinf=0x3f3f3f3f3f3f3f3f;
const int m=19;
int n,Q,a[maxn];
struct Basis{int b[m+1],tim[m+1],tot;il void init(){mem(b,0),mem(tim,0),tot=0;}il void ins(int x,int t){per(i,m,0)if((x>>i)&1){if(!b[i])return b[i]=x,tim[i]=t,++tot,void();if(t>tim[i])swap(b[i],x),swap(tim[i],t);x^=b[i];}}il int qry(int lft,int k){--k;if(k<=0)return 0;int num=0;rep(i,0,m)if(tim[i]>=lft)++num;int res=0;per(i,m,0)if(tim[i]>=lft){if((k>>(num-1))&1)ckmx(res,res^b[i]);else ckmn(res,res^b[i]);--num;}return res;}//小于等于x的数有几个 il int getrk(int lft,int x){if(x<0)return 0;vector<int>v(m+1,0);rep(i,0,m)if(tim[i]>=lft)v[i]=1;rep(i,1,m)v[i]+=v[i-1];int res=0,nw=0;per(i,m,0){if(tim[i]>=lft){if((x>>i)&1){nw+=1<<(v[i]-1);ckmx(res,res^b[i]);}else{ckmn(res,res^b[i]);}}else{if(((res>>i)&1)&&(~(x>>i)&1))return nw;}}return nw+1;}void operator=(const Basis &p){tot=p.tot;rep(i,0,m)b[i]=p.b[i],tim[i]=p.tim[i];}
} c[maxn];
vector<pii>ql[maxn];
vector<int>vec[maxn],v;
struct pq{priority_queue<int>q1,q2;void clear(){while(!q1.empty())q1.pop();while(!q2.empty())q2.pop();}void push(int x){q1.push(x);}void erase(int x){q2.push(x);}bool empty(){while(!q1.empty()&&!q2.empty()&&q1.top()==q2.top())q1.pop(),q2.pop();return q1.empty();}int top(){assert(!q1.empty());return q1.top();}
}q[m+2];
bool ans[maxn];
void init(){rep(i,0,n)c[i].init(),ql[i].clear(),vec[i].clear();rep(i,0,m+1)q[i].clear();
}
inline void solve_the_problem(){n=rd(),Q=rd(),init();rep(i,1,n)a[i]=rd();rep(i,1,n)c[i]=c[i-1],c[i].ins(a[i],i);]rep(i,1,n)rep(j,0,m)if(c[i].tim[j])vec[c[i].tim[j]].pb(i);rep(i,1,Q){int l=rd(),r=rd();ql[l].pb(mp(r,i));}rep(i,1,n)q[c[i].tot].push(i);rep(l,1,n){for(int i:vec[l-1]){q[c[i].tot].erase(i);--c[i].tot;q[c[i].tot].push(i);}for(pii _:ql[l]){int r=_.fi,id=_.se;v.clear();for(int i=1;i<=m+1&&!q[i].empty();++i){int p=q[i].top();v.pb(min(p,r));if(p>r)break;}bool ok=1;int lst=l-1,ed=-1;rep(i,0,(int)v.size()-1){int len=v[i]-lst;lst=v[i];int rk=c[v[i]].getrk(l,ed);if(rk+len>(1<<c[v[i]].tot)){ok=0;break;}ed=c[v[i]].qry(l,rk+len);}ans[id]=ok;}}rep(i,1,Q)ans[i]?PY:PN;
}
bool Med;
signed main(){
//	freopen(".in","r",stdin);freopen(".out","w",stdout);fprintf(stderr,"%.3lfMB\n",(&Mbg-&Med)/1048576.0);int _=rd();while(_--)solve_the_problem();
}
/**/

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/908132.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

提到链接,你能想到什么

linux中的链接文件和虚拟机的克隆技术一.链接文件 在了解链接文件两种类型之前,必须先了解的知识: 文件在Linux中被分成两部分:数据(data block)和文件元数据(inode) inode与block 每个文件都有一个 inode(索引节…

实用指南:容器逃逸漏洞

实用指南:容器逃逸漏洞pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !important; font-family: "Consolas", "Monaco", &qu…

实用指南:容器逃逸漏洞

实用指南:容器逃逸漏洞pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !important; font-family: "Consolas", "Monaco", &qu…

深入解析:卷对卷(Roll-to-Roll,R2R)技术的应用领域和技术进展

pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !important; font-family: "Consolas", "Monaco", "Courier New", …

深入解析:卷对卷(Roll-to-Roll,R2R)技术的应用领域和技术进展

pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !important; font-family: "Consolas", "Monaco", "Courier New", …

三种方式处理SpringBoot全局异常

在SpringBoot开发web项目时,异常处理是必不可少的一部分。在应用中,异常可能出现在任何地方,例如在控制层,服务层,数据访问层等等。如果不对异常进行处理可能会导致应用崩溃或者出现未知的错误。因此对于异常的处…

解题记录说是 | P3695 CYaRon!语

小模拟link 起因 闲的没事找模拟做,发现这个部分分的档次很多,而且好想挺好做,就做了。 是分着部分分做的,而且完全就是那种苦(封装各种实现)尽甘(飞速写完 ihu hor while)来的感觉,很爽的。 code goes first…

分享一个极度精简的绿色的 五笔输入法

这个输入法是本人修改过的 柚子输入法,极度精简,绿色无需安装,释放之后即可使用. 功能说明请看 压缩包的说明文件. 通过网盘分享的文件:youziIME2025-9-19.rar 链接: 百度网盘 如果需要修改功能,你需要懂一点Auto…

[GDKOI2023 提高组] 游戏 题解

一种比较简短的写法: 拉出直径,再在直径的每一个点上跑一下最长链,为 $ mx_i$ 这里设三点的路径交点为 \(rt\)。 假设 \(rt \rightarrow u,v,w\) 的距离为 \(dis1,dis2,dis3\) 。 容易知道 \(dis1 = (x+y-z)/2,dis2…

CSP-J/S 2025 游记

突然发现今年忘记写游记了…… [2025.6.30,2025.8.1) 中考。 [2025.8.1,2025.8.31] 暑假集训 15 天,一天比赛一天专题。早上 8:00 到机房训到 12:00 然后和高三抢饭,下午 14:00-17:00 继续搞,晚上 19:00-22:00。只有…

2025.9.19 计数dp小记

[CQOI2011] 放棋子 本题有一个性质,棋子间互不关联,又因为数据范围小,很容易 \(dp\) 记 \(f_{p,i,j}\) 表示考虑前 \(p\) 种颜色,放了 \(i\) 行 \(j\) 列的方案数 则枚举 \(p\) 放了几行几列,有 \[f_{p,i,j} = \s…

实用指南:AI推理范式:从CoT到ReAct再到ToT的进化之路

实用指南:AI推理范式:从CoT到ReAct再到ToT的进化之路pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !important; font-family: "Consolas&q…

sign up - Gon

如果注册github时出现 Unable to verify your captcha response. Please visit https://docs.github.com/articles/troubleshooting-connectivity-problems/#troubleshooting-the-captcha for troubleshooting informa…

ctfshow web入门 信息搜集

有些题目会了就没写了,只记录一下自己不会写的题目,不过信息搜集还是很重要的ctfshow web3(自带网络工具包查看数据)查看源码什么也没有扫目录也什么都没有只能说信息收集能力还欠佳, 我们可以先尝试使用浏览器自带…

完整教程:数据结构:单链表的应用(力扣算法题)第二章

完整教程:数据结构:单链表的应用(力扣算法题)第二章pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !important; font-family: "Consolas&…

CF2039E Shohag Loves Inversions

CF2039E Shohag Loves Inversions 题意: 给你一个数列,初始数列为 $ a = [0, 1] $ ,现在重复进行以下操作若干次:将当前数组中逆序对个数 \(k\) 插入当前数组中任意一个位置,包括开头或者结尾。其中 \(n\le 1e6\)…

深入解析:sqlite3的加解密全过程

pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !important; font-family: "Consolas", "Monaco", "Courier New", …

U522155 板垣 カノエ is WATCHING YOU std

U522155 板垣 カノエ is WATCHING YOU #include<bits/stdc++.h> #define int long long #define add(a,b) to[++ tot] = b,nxt[tot] = h[a],h[a] = tot #define con putchar_unlocked( ) #define ent putchar_u…

ctfshow web

ctfshow里面免费的web题不写白不写ctf.show_红包题第二弹1打开题目显示这样 看看源码有无提示可以看到提示了cmd参数,那我们就随便传点东西看看会有什么回显又是代码审计,可以看到大小写字母过滤后只有小写p可以使用…

代码随想录算法训练营第三天 | leetcode 203 707 206

203移除链表元素 注意事项:java语言的访问链表和数据用的是".",空指针是小写的null。在删除链表时先对表头进行判断避免表头是null和表头元素是要删除的元素,下面进行循环寻找时要注意判断指针的下一个指针…