RT,RE了,改不出来,模拟赛打完之后回来看题解只会三十分的,一上午了这三十分还没调出来QAQ 蒟蒻的RE
需要大佬的帮助QWQ
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <math.h>
#include <algorithm>
#include <istream>
#include <string>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <string.h>
#include <map>
#include <unordered_map>
#include <bitset>
using namespace std;
#define lc(x) sgt[x].lc
#define rc(x) sgt[x].rc
#define w(x) sgt[x].w
vector<int>g[100030];
int n,p;
int m;
int a[100030];
unsigned int SA, SB, SC;
unsigned int rng61(){
SA ^= SA << 16;
SA ^= SA >> 5;
SA ^= SA << 1;
unsigned int t = SA;
SA = SB;
SB = SC;
SC ^= t ^ SA;
return SC;
}
inline void addedge(int x,int y){
g[x].push_back(y);
g[y].push_back(x);
}
void gen(){
scanf("%d%d%u%u%u", &n, &p, &SA, &SB, &SC);
for(int i = 2; i <= p; i++)
addedge(i - 1, i);
for(int i = p + 1; i <= n; i++)
addedge(rng61() % (i - 1) + 1, i);
for(int i = 1; i <= n; i++)
a[i] = rng61() % n + 1;
}
struct node{int w,lc,rc;}sgt[2000300<<2];
int cnt=0;
inline int nnd(int x=0){
cnt++;
sgt[cnt]={x,0,0};
return cnt;
}
inline void upd(int x){
sgt[x].w=sgt[lc(x)].w+sgt[rc(x)].w;
}
inline int mod(int &x,int l,int r,int loc){
if(!x) x=nnd();
int p=++cnt;
sgt[p]=sgt[x];
sgt[p].w++;
if(l==r)return p;
int mid=l+r>>1;
if(loc<=mid)lc(p)=mod(lc(p),l,mid,loc);
else rc(p)=mod(rc(p),mid+1,r,loc);
upd(p);
return p;
}
inline int mod2(int &x,int l,int r,int loc,int v){
if(!x) x=nnd();
int p=++cnt;
sgt[p]=sgt[x];
sgt[p].w=v;
if(l==r)return p;
int mid=l+r>>1;
if(loc<=mid)lc(p)=mod(lc(p),l,mid,loc);
else rc(p)=mod(rc(p),mid+1,r,loc);
return p;
}
int fa[100030][32];
int dep[100030];
int rt[100030];
int pre[100030];
int rt2[100030];
inline void dfs(int u){
dep[u]=dep[fa[u][0]]+1;
int k=g[u].size();
int t=pre[a[u]];
rt[u]=mod(rt[fa[u][0]],1,n,pre[a[u]]);
rt2[u]=mod2(rt2[fa[u][0]],1,n,a[u],u);
pre[a[u]]=u;
for(int i=1;i<=20;i++)
fa[u][i]=fa[fa[u][i-1]][i-1];
for(int i=0;i<k;i++){
int v=g[u][i];
if(v==fa[u][0])continue;
fa[v][0]=u;
dfs(v);
}
pre[a[u]]=t;
}
inline int LCA(int x,int y){
if(dep[x]<dep[y])swap(x,y);
int l=20;
while(dep[x]>dep[y]){
if(dep[fa[x][l]]>=dep[y])x=fa[x][l];l--;}
if(x==y) return y;
l=20;
while(l>=0){
if(fa[x][l]!=fa[y][l]){
x=fa[x][l];
y=fa[y][l];
}
l--;
}
return fa[x][0];
}
inline int get(int tx,int ty,int l,int r,int loc){
if(l==r) return w(ty)-w(tx);
int mid=l+r>>1;
if(loc<=mid)return get(lc(tx),lc(ty),l,mid,loc);
else return w(lc(ty))-w(lc(tx))+
get(rc(tx),rc(ty),mid+1,r,loc);
}
inline int get2(int x,int l,int r,int loc){
if(l==r) return w(x);
int mid=l+r>>1;
if(loc<=mid) return get2(lc(x),l,mid,loc);
else return get2(rc(x),mid+1,r,loc);
}
inline int solve1(int x,int y){
if(dep[x]>dep[y]) swap(x,y);
int lca=LCA(x,y);
int res=get(rt[lca],rt[y],1,n,lca);
set<int>s;
while(x!=lca){
if(!s.count(a[x])&&get2(rt2[x],1,n,a[x])<=lca)res++;
s.insert(a[x]);
x=fa[x][0];
}
return res;
}
signed main() {
int T;
scanf("%d",&T);
for(;T>0;T--){
for(int i=1;i<=n;i++)g[i].clear();
gen();
scanf("%d",&m);
memset(fa,0,sizeof(fa));
dfs(1);
int op, x,y;
for(int i=1;i<=m;i++){
scanf("%d%d%d",&op,&x,&y);
if(op==1)
printf("%d\n",solve1(x,y));
else cout<<"%%%yywd AK ioi%%%\n";
}
}
return 0;
}