QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#468613#1281. Longest Common SubsequenceliangjiaqiWA 54ms18064kbC++142.7kb2024-07-08 21:50:362024-07-08 21:50:41

Judging History

你现在查看的是最新测评结果

  • [2024-07-08 21:50:41]
  • 评测
  • 测评结果:WA
  • 用时:54ms
  • 内存:18064kb
  • [2024-07-08 21:50:36]
  • 提交

answer

#include<bits/stdc++.h>
#define il inline
#define ui unsigned int
#define ll long long
#define ull unsigned ll
#define lll __int128
#define db double
#define ldb long double
#define pii pair<int,int>
#define vi vector<int>
#define vpii vector<pii>
#define fir first
#define sec second
#define gc getchar
#define pc putchar
#define mst(a,x) memset(a,x,sizeof a)
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define pct __builtin_popcount
using namespace std;
const int N=1e6+10,INF=0x3f3f3f3f,MOD=1e9+7;
const ll INFll=0x3f3f3f3f3f3f3f3f;
il int rd() {int x=0,f=1; char ch=gc(); while(ch<'0'||ch>'9') {if(ch=='-') f=-1; ch=gc();} while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=gc(); return x*f;}
il ll rdll() {ll x=0; int f=1; char ch=gc(); while(ch<'0'||ch>'9') {if(ch=='-') f=-1; ch=gc();} while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=gc(); return x*f;}
il void wr(int x) {if(x<-2147483647) {printf("-2147483648"); return;} if(x<0) {pc('-'),wr(-x); return;} if(x<10) {pc(x+'0'); return;} wr(x/10),pc(x%10+'0');}
il void wrll(ll x) {if(x<-9223372036854775807) return (void)printf("-9223372036854775808"); if(x<0) return pc('-'),wrll(-x); if(x<10) return (void)pc(x+'0'); wrll(x/10),pc(x%10+'0');}
il void wr(int x,char *s) {wr(x),printf("%s",s);}
il void wrll(ll x,char *s) {wrll(x),printf("%s",s);}
il int vmod(int x) {return x>=MOD?x-MOD:x;}
il int vadd(int x,int y) {return vmod(x+y);}
il int vsub(int x,int y) {return vmod(x-y+MOD);}
il int vmul(int x,int y) {return 1ll*x*y%MOD;}
int n,m,k,cp,cq,cs,ct,ans,a[N],b[N],c[N],d[N],p[N],q[N],s[N],t[N];
struct BIT {
	int siz,tr[N<<1];
	il int lbt(int x) {return x&-x;}
	il void upd(int x,int y) {for(;x<=siz;x+=lbt(x)) tr[x]=max(tr[x],y);}
	il int qry(int x) {int res=-INF; for(;x;x-=lbt(x)) res=max(res,tr[x]); return res;}
} S,T;
void QwQ() {
	n=rd(),m=rd(),k=max(n,m),cp=cq=cs=ct=ans=0,S.siz=T.siz=k<<1; for(int i=1;i<=S.siz;i++) S.tr[i]=T.tr[i]=-INF;
	for(int i=1;i<=n;i++) a[i]=rd(),c[i]=c[i-1]+(a[i]==2); for(int i=1;i<=m;i++) b[i]=rd(),d[i]=d[i-1]+(b[i]==2);
	q[0]=n+1; for(int i=1;i<=n;i++) if(a[i]==1) p[++cp]=i; for(int i=n;i;i--) if(a[i]==3) q[++cq]=i; for(int i=cp+1;i<=n;i++) p[i]=n+1; for(int i=cq+1;i<=n;i++) q[i]=0;
	t[0]=m+1; for(int i=1;i<=m;i++) if(b[i]==1) s[++cs]=i; for(int i=m;i;i--) if(b[i]==3) t[++ct]=i; for(int i=cs+1;i<=m;i++) s[i]=m+1; for(int i=ct+1;i<=m;i++) t[i]=0;
	for(int l=0,r=min(n,m);~r;r--) {
		for(;l<=n&&l<=m&&p[l]<q[r]&&s[l]<t[r];l++) S.upd(c[p[l]]-d[s[l]]+k,l-d[s[l]]),T.upd(d[s[l]]-c[p[l]]+k,l-c[p[l]]);
		ans=max({ans,r+c[q[r]-1]+T.qry(d[t[r]-1]-c[q[r]-1]+k),r+d[t[r]-1]+T.qry(c[q[r]-1]-d[t[r]-1]+k)});
	}
	wr(ans,"\n");
}
signed main() {
	int T=rd(); while(T--) QwQ();
}
//

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 18064kb

input:

3
3 3
1 2 3
1 2 3
3 3
1 1 1
1 1 2
3 3
1 3 2
1 2 3

output:

3
2
2

result:

ok 3 tokens

Test #2:

score: -100
Wrong Answer
time: 54ms
memory: 18060kb

input:

139889
1 10
2
2 1 2 2 3 1 1 2 3 3
7 1
3 2 3 3 1 1 2
2
6 1
2 1 3 1 1 1
1
8 7
3 1 3 3 2 2 3 1
3 2 2 1 3 3 3
10 3
3 2 1 1 2 2 1 1 1 1
3 1 1
5 2
1 2 1 3 1
1 2
1 4
1
3 3 3 3
7 2
3 1 2 1 2 2 3
3 2
6 2
3 1 1 2 1 3
1 3
1 4
1
3 1 1 3
4 2
2 3 2 3
1 3
1 8
1
1 1 3 1 3 3 3 1
4 1
1 3 3 3
1
10 10
3 1 2 1 2 2 2 2 1...

output:

1
1
1
4
1
2
0
1
2
1
1
1
1
6
1
0
1
2
2
3
4
4
1
1
1
0
2
2
3
5
4
1
1
3
2
0
2
1
3
1
1
1
3
1
1
1
3
2
1
2
1
4
1
2
2
1
3
1
1
2
3
1
3
4
4
2
2
1
0
1
2
4
3
2
1
1
2
3
1
2
2
1
4
2
4
2
1
2
3
2
5
2
1
3
1
3
1
2
1
2
2
4
3
2
0
1
1
3
2
3
2
4
0
0
2
3
1
2
0
5
1
4
1
1
3
0
1
0
1
1
1
1
3
2
2
2
3
2
3
1
2
2
3
2
1
1
3
3
2
3
...

result:

wrong answer 5th words differ - expected: '2', found: '1'