CSP-S2024 T4 arena
这个做法来看,对数做法到线性做法的跨度还比较大(?)
将打擂的过程看成一颗线段树。
定义“不定人”为一个
性质 1:一个子树内的可能胜者要么唯一且是固定人,要么存在一个不定人。
若可能胜者有两个且无不定人,那么这两个人在合并的过程中必然会进行一次打擂。
性质 2:一个人不可能成为胜者当且仅当:
- 某次打擂兄弟子树的胜者唯一且是固定人,且兄弟子树守擂,且守擂成功。
- 某次打擂自己是擂主,但守擂失败。
显然,若一个人不满足以上两个条件,那么这个人就可能成为胜者。
考虑每一个
性质 3:一个
当某次与兄弟子树打擂失败后,这个
从兄弟子树内胜者确定的时刻开始便不会成为可能胜者。
首先遍历线段树预处理出来每个子树内的确定胜者和确定胜者的时刻,然后我们考虑线段树从上往下递归求答案。假设当前节点的所有点的可能贡献区间为
由于线段树总点数
点击查看代码
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
#include<map>
#include<vector>
#include<queue>
#include<stack>
#include<bitset>
#include<set>
#include<ctime>
#include<random>
#include<cassert>
#define IOS ios::sync_with_stdio(false)
#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 pc putchar
#define pb emplace_back
#define un using namespace
#define popc __builtin_popcountll
#define all(x) x.begin(),x.end()
#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 mem(x,y) memset(x,y,sizeof x)
//#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>;
inline int rd(){
int x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+ch-48;ch=getchar();}return x*f;
}
template<typename T>
inline void write(T x,char ch='\0'){
if(x<0){x=-x;putchar('-');}
int y=0;char z[40];
while(x||!y){z[y++]=x%10+48;x/=10;}
while(y--)putchar(z[y]);if(ch!='\0')putchar(ch);
}
bool Mbg;
const int maxn=131080,maxm=4e5+5,maxk=18,inf=0x3f3f3f3f;
const long long llinf=0x3f3f3f3f3f3f3f3f;
int n,Q,K;
int a[maxn],b[maxn];
char s[maxk][maxn];
i64 c[maxn];
int X_qwq[maxn];
//能确定胜者的最小时刻
int t[maxn<<2],g[maxn<<2];
inline void build(int p,int R,int G){
if(R==0)return t[p]=g[p]=G+1,void();
build(lson(p),R-1,lson(G)),build(rson(p),R-1,rson(G));
if(s[R][G]=='0'){
if(a[g[lson(p)]]>=R){
t[p]=t[lson(p)],g[p]=g[lson(p)];
}else{
t[p]=t[rson(p)],g[p]=g[rson(p)];
}
}else{
if(a[g[rson(p)]]>=R){
t[p]=t[rson(p)],g[p]=g[rson(p)];
}else{
t[p]=t[rson(p)],g[p]=g[lson(p)];
}
}
}
inline void qry(int p,int R,int G,int lim,int l,int r){
if(l>=r)return;
if(R==0){
const int id=G+1;
if(a[id]>=lim)c[l]+=id,c[r]-=id;
else if(l<id)c[l]+=id,c[min(r,id)]-=id;
return;
}
if(s[R][G]=='0'){
qry(lson(p),R-1,lson(G),max(lim,R),l,r);
qry(rson(p),R-1,rson(G),lim,l,min(r,a[g[lson(p)]]>=R?t[lson(p)]:inf));
}else{
qry(rson(p),R-1,rson(G),max(lim,R),l,r);
qry(lson(p),R-1,lson(G),lim,l,min(r,a[g[rson(p)]]>=R?t[rson(p)]:inf));
}
}
inline void solve_the_problem(){
rep(i,0,3)X_qwq[i]=rd();
rep(i,1,n)a[i]^=X_qwq[i%4];
build(1,K,0);
rep(i,1,n)c[i]=0;
rep(i,0,K)qry((1<<i),K-i,0,0,i==K?1:((1<<(K-i-1))+1),(1<<(K-i))+1);
rep(i,1,n)c[i]+=c[i-1];
i64 ans=0;
// rep(i,1,n)write(c[i],32);
rep(i,1,Q)ans^=c[b[i]]*i;
write(ans,10);
rep(i,1,n)a[i]^=X_qwq[i%4];
}
bool Med;
signed main(){
// freopen(".in","r",stdin);freopen(".out","w",stdout);
// fprintf(stderr,"%.3lfMB\n",(&Mbg-&Med)/1048576.0);
n=rd(),Q=rd();
rep(i,1,n)a[i]=rd();
rep(i,1,Q)b[i]=rd();
K=ceil(log2(n));
rep(i,1,K)scanf("%s",s[i]);
int _=rd();
while(_--)solve_the_problem();
}
/*
*/
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!