[THUPC 2026 初赛] 庭中有奇树
前言
卡 gp_hash_table 的出题人是【数据删除】。
题目分析
发现树的高度很小,考虑暴力修改。
对于一个点维护子树内不考虑祖先的操作的值和一个懒标记。由于对一个子树异或了
所以现在问题是需要知道某次操作对这个子树的异或的影响。如果这个子树原先值是
还有一个小问题,直接从根往上异或这个变化量不太对,因为我们维护的时候只考虑了子树内的操作,所以此时子树内的值不是真正正确的。所以对于一个操作数
注意存的时候手写哈希,不然会被卡。时间复杂度
代码
#include<bits/stdc++.h>
#include<bits/extc++.h>
#define int long long
#define ALL(x) (x).begin(),(x).end()
using namespace std;
using namespace __gnu_pbds;
mt19937_64 rnd(chrono::steady_clock::now().time_since_epoch().count());
struct Hsh{
unsigned int operator()(unsigned int x)const{
static const unsigned int s1=rnd(),s2=rnd(),s3=rnd();
x+=s1;
x=(x^(x>>33))*s2;
x=(x^(x>>30))*s3;
return x;
}
};
int n,q;
vector<tuple<int,int,int> >queries;
__inline int getfa(int x){
if(x<=1)
return 0;
int fath=sqrt(2*x-2);
if(fath*(fath-1)/2+2<=x&&x<=fath*(fath+1)/2+1)
return fath;
else
return fath+1;
}
__inline int qsiz(int id){
int ret(1);
__int128 l(id),r(id);
while(r<=n){
l=l*(l-1)/2+2,r=r*(r+1)/2+1;
ret+=max(min(((__int128)(n)),r)-l+1,((__int128)(0)));
}
return ret;
}
struct Tree{
int fa,val,tag,siz;
Tree(){}
Tree(int id):fa(getfa(id)),val(0),tag(0),siz(qsiz(id)){}
};
gp_hash_table<int,Tree,Hsh>tr;
__inline int qtag(int x){
int ret(0);
while(x)
ret|=tr[x].tag,x=tr[x].fa;
return ret;
}
__inline void modify(int x,int val){
val&=(~qtag(x));
int v(((tr[x].val&(~val))+(val*(tr[x].siz&1)))^tr[x].val);
tr[x].tag|=val;
while((x=tr[x].fa))
tr[x].val^=v;
return;
}
__inline int query(int x){
int tag(qtag(x));
return(tr[x].val&(~tag))+(tag*(tr[x].siz&1));
}
string program(){
cin.tie(nullptr)->ios::sync_with_stdio(0);
cin>>n>>q;
for(int i(1),o,x,c;i<=q;i++){
cin>>o>>x;
if(o==1)
cin>>c;
queries.push_back(make_tuple(o,x,c));
}
for(auto[H17,p,_H17_]:queries)
while(p&&(!tr[p].fa)){
tr[p]=Tree(p);
p=tr[p].fa;
}
for(auto[o,x,c]:queries){
if(o==1)
modify(x,c);
else
println("{}",query(x));
}
return"H17";
}
string H17(program());
signed main(){
return 0;
}