赛时做法,不过被狠狠卡常,改改块长可以过的。明年再战呃呃呃。
注意到题目很不能做到 的复杂度,因为该问题严格不劣于 DAG 可达性问题,而这个只能做到 ,我们可以先预处理出所有 表示是否存在 的路径。
进一步考虑原问题,可以进行操作分块,具体的我们对于 按照 进行分块。我们处理一个时间区间 的所有贡献,总共重复 次该过程。
考虑将 中 操作涉及的所有 称为关键点。那么对于 中操作 的 可达的所有 而言,分为关键点和非关键点,对于关键点可以直接对这 个数进行暴力判定以及暴力修改这些的 ,问题在于处理所有非关键点。
从 是排列的性质以及询问要求 中入手,不难想到进行分块。具体而言,对于 按照 分块,且相当于以 为这个数组的下标。那么对于 拆分成的是 个整块以及 个零散位置。对于整块可以处理: 表示 可以到达的 使得 在第 个整块中最大的 的值。那么预处理的复杂度就是 ,询问的复杂度是 ,对于一个零散点显然可以 判断。
视 同阶,时间复杂度是 ,理论上可以取 来分析到 ,但是实现上的 是严重依赖于实现来进行调整的。
代码赛后重写的。
#include<bits/stdc++.h>
#define F(i,a,b) for(int i=(a);i<=(b);++i)
#define dF(i,a,b) for(int i=(a);i>=(b);--i)
#define ull unsigned long long
#define uint unsigned
#define inf 1000000000
#define infll 1000000000000000000ll
#define pb push_back
#define mkp make_pair
#define pii pair<int,int>
#define ll long long
#define fi first
#define se second
#define SZ(x) ((int)x.size())
#define lowbit(x) ((x)&(-(x)))
#define rep(i,a,b,c) for(int i=(a);i<=(b);i+=(c))
#define per(i,a,b,c) for(int i=(a);i>=(b);i-=(c))
using namespace std;
void fre(){
// freopen("recall.in","r",stdin),freopen("recall.out","w",stdout);
}
char buf[1<<20],*p1,*p2;
#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<20,stdin),p1==p2)?EOF:*p1++)
namespace Fastio{struct Reader{template<typename T>Reader&operator>>(T&x){x=0;short f=1;char c=getchar();while(c<'0'||c>'9'){if(c=='-')f*=-1;c=getchar();}while(c>='0'&&c<='9')x=(x<<3)+(x<<1)+(c^48),c=getchar();x*=f;return*this;}Reader&operator>>(double&x){x=0;double t=0;short f=1,s=0;char c=getchar();while((c<'0'||c>'9')&&c!='.'){if(c=='-')f*=-1;c=getchar();}while(c>='0'&&c<='9'&&c!='.')x=x*10+(c^48),c=getchar();if(c=='.')c=getchar();else{x*=f;return*this;}while(c>='0'&&c<='9')t=t*10+(c^48),s++,c=getchar();while(s--)t/=10.0;x=(x+t)*f;return*this;}Reader&operator>>(long double&x){x=0;long double t=0;short f=1,s=0;char c=getchar();while((c<'0'||c>'9')&&c!='.'){if(c=='-')f*=-1;c=getchar();}while(c>='0'&&c<='9'&&c!='.')x=x*10+(c^48),c=getchar();if(c=='.')c=getchar();else{x*=f;return*this;}while(c>='0'&&c<='9')t=t*10+(c^48),s++,c=getchar();while(s--)t/=10.0;x=(x+t)*f;return*this;}Reader&operator>>(__float128&x){x=0;__float128 t=0;short f=1,s=0;char c=getchar();while((c<'0'||c>'9')&&c!='.'){if(c=='-')f*=-1;c=getchar();}while(c>='0'&&c<='9'&&c!='.')x=x*10+(c^48),c=getchar();if(c=='.')c=getchar();else{x*=f;return*this;}while(c>='0'&&c<='9')t=t*10+(c^48),s++,c=getchar();while(s--)t/=10.0;x=(x+t)*f;return*this;}Reader&operator>>(char&c){c=getchar();while(c==' '||c=='\n'||c=='\r')c=getchar();return*this;}Reader&operator>>(char*str){int len=0;char c=getchar();while(c==' '||c=='\n'||c=='\r')c=getchar();while(c!=' '&&c!='\n'&&c!='\r')str[len++]=c,c=getchar();str[len]='\0';return*this;}Reader&operator>>(string&str){str.clear();char c=getchar();while(c==' '||c=='\n'||c=='\r')c=getchar();while(c!=' '&&c!='\n'&&c!='\r')str.push_back(c),c=getchar();return*this;}Reader(){}}cin;const char endl='\n';struct Writer{const int Setprecision=6;typedef int mxdouble;template<typename T>Writer&operator<<(T x){if(x==0){putchar('0');return*this;}if(x<0)putchar('-'),x=-x;static short sta[40];short top=0;while(x>0)sta[++top]=x%10,x/=10;while(top>0)putchar(sta[top]+'0'),top--;return*this;}Writer&operator<<(double x){if(x<0)putchar('-'),x=-x;mxdouble _=x;x-=(double)_;static short sta[40];short top=0;while(_>0)sta[++top]=_%10,_/=10;if(top==0)putchar('0');while(top>0)putchar(sta[top]+'0'),top--;putchar('.');for(int i=0;i<Setprecision;i++)x*=10;_=x;while(_>0)sta[++top]=_%10,_/=10;for(int i=0;i<Setprecision-top;i++)putchar('0');while(top>0)putchar(sta[top]+'0'),top--;return*this;}Writer&operator<<(long double x){if(x<0)putchar('-'),x=-x;mxdouble _=x;x-=(long double)_;static short sta[40];short top=0;while(_>0)sta[++top]=_%10,_/=10;if(top==0)putchar('0');while(top>0)putchar(sta[top]+'0'),top--;putchar('.');for(int i=0;i<Setprecision;i++)x*=10;_=x;while(_>0)sta[++top]=_%10,_/=10;for(int i=0;i<Setprecision-top;i++)putchar('0');while(top>0)putchar(sta[top]+'0'),top--;return*this;}Writer&operator<<(__float128 x){if(x<0)putchar('-'),x=-x;mxdouble _=x;x-=(__float128)_;static short sta[40];short top=0;while(_>0)sta[++top]=_%10,_/=10;if(top==0)putchar('0');while(top>0)putchar(sta[top]+'0'),top--;putchar('.');for(int i=0;i<Setprecision;i++)x*=10;_=x;while(_>0)sta[++top]=_%10,_/=10;for(int i=0;i<Setprecision-top;i++)putchar('0');while(top>0)putchar(sta[top]+'0'),top--;return*this;}Writer&operator<<(char c){putchar(c);return*this;}Writer&operator<<(char*str){int cur=0;while(str[cur])putchar(str[cur++]);return*this;}Writer&operator<<(const char*str){int cur=0;while(str[cur])putchar(str[cur++]);return*this;}Writer&operator<<(string str){int st=0,ed=str.size();while(st<ed)putchar(str[st++]);return*this;}Writer(){}}cout;}using namespace Fastio;
#define cin Fastio::cin
#define cout Fastio::cout
#define endl Fastio::endl
inline void chkmax(int &x,int y){ x=max(x,y); }
const int mod=998244353,maxn=100005;
int btcnt;
struct bitsett{
ull a[(maxn>>6)+1];
inline void init(){ memset(a,0,sizeof a); }
inline void upd(int x){ a[x>>6]|=(1ull<<(x&63)); }
inline void orr(bitsett &y){ F(i,0,btcnt)a[i]|=y.a[i]; }
inline bool ask(int x){ return (a[x>>6]>>(x&63))&1; }
}to[maxn];
vector<int>g[maxn];
int n,m,zsy,ans[maxn],a[maxn],b[maxn],rb[maxn];
const int B=2800;
struct Oper{
int op,x,l,r;
}q[maxn];
bool qtag[maxn],ctag[maxn];
vector<int>qu[maxn];
int bl[maxn],br[maxn],bel[maxn],f[maxn][maxn/B+1],ra[maxn],qwq[maxn];
inline void Solve(int l,int r){
F(i,1,n)qtag[i]=ctag[i]=ra[i]=0,qu[i].clear();
F(i,l,r){
if(q[i].op<=2)ctag[q[i].l]=ctag[q[i].r]=1;
else qtag[q[i].x]=1,qu[q[i].x].push_back(i);
}
F(i,1,n)memset(f[i],0,sizeof f[i]);
F(i,1,n)if(!ctag[i])ra[a[i]]=i;
dF(u,n,1){
if(!ctag[u])f[u][bel[a[u]]]=b[u];
for(int v:g[u])F(i,1,bel[n])chkmax(f[u][i],f[v][i]);
if(qtag[u])for(int id:qu[u]){
const int l=q[id].l,r=q[id].r;
if(bel[l]==bel[r]){
F(j,l,r)if(to[u].ask(ra[j]))chkmax(ans[id],b[ra[j]]);
} else{
F(j,bel[l]+1,bel[r]-1)chkmax(ans[id],f[u][j]);
F(j,l,br[bel[l]])if(to[u].ask(ra[j]))chkmax(ans[id],b[ra[j]]);
F(j,bl[bel[r]],r)if(to[u].ask(ra[j]))chkmax(ans[id],b[ra[j]]);
}
}
}
vector<int>vec;
F(i,1,n)if(ctag[i])vec.push_back(i);
F(i,l,r){
if(q[i].op==1)swap(a[q[i].l],a[q[i].r]);
else if(q[i].op==2)swap(b[q[i].l],b[q[i].r]);
else{
const int u=q[i].x,l=q[i].l,r=q[i].r;
for(const int &v:vec)if(l<=a[v]&&a[v]<=r&&to[u].ask(v))chkmax(ans[i],b[v]);
}
}
}
void Solve_(){
cin>>n>>m>>zsy,btcnt=n>>6;
F(i,1,n)to[i].init(),g[i].clear();
F(i,1,m){ int u,v;cin>>u>>v,g[u].push_back(v); }
F(i,1,n)cin>>a[i];
F(i,1,n)cin>>b[i];
dF(u,n,1){ to[u].upd(u);for(int v:g[u])to[u].orr(to[v]); }
F(i,1,zsy){
cin>>q[i].op;
if(q[i].op<=2)cin>>q[i].l>>q[i].r;
else cin>>q[i].x>>q[i].l>>q[i].r;
ans[i]=0;
}
F(i,1,n)bel[i]=(i-1)/B+1,br[bel[i]]=i;
dF(i,n,1)bl[bel[i]]=i;
const int B2=3200;
F(i,1,(zsy-1)/B2+1)Solve((i-1)*B2+1,min(i*B2,zsy));
F(i,1,zsy)if(q[i].op==3)cout<<ans[i]<<'\n';
}
signed main(){
fre();
int zsy=1; cin>>zsy>>zsy;
F(i,1,zsy)Solve_();
}