这题惩罚我这种经常不管常数的懒人
直接 1e6 TLE 如果1e5对数组枚举过
诶其实很想吐槽些伤心事,但是还是不想在博客上吐口水
不管今年比赛结果如何 请享受比赛
#include<bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int MAXN = 1e6+5;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
int N,M;
int A[100005], B[100005];
int ha[MAXN], hb[MAXN];
int fa[MAXN], fb[MAXN];
int main(){
int T; scanf("%d",&T);
int ca = 0;
while(T--) {
++ca;
scanf("%d %d",&N,&M);
for(int i = 1; i <= N; ++i) scanf("%d",&A[i]);
for(int i = 1; i <= M; ++i) scanf("%d",&B[i]);
for(int i = 1; i <= N; ++i) {
if(fa[A[i]-1] == ca) ha[A[i]] = ha[A[i]-1];
else ha[A[i]] = A[i];
fa[A[i]] = ca;
}
for(int i = 1; i <= M; ++i) {
if(fb[B[i]-1] == ca) hb[B[i]] = hb[B[i]-1];
else hb[B[i]] = B[i];
fb[B[i]] = ca;
}
int ans = 0;
for(int i = N; i >= 1; --i) {
if(ans > i) break;
int j = A[i];
if(fa[j]==ca && fb[j]==ca) ans = max(ans, j-max(hb[j],ha[j])+1 );
}
printf("%d
",ans);
}
return 0;
}