QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#468515 | #1281. Longest Common Subsequence | maojun | WA | 113ms | 20312kb | C++20 | 1.6kb | 2024-07-08 21:14:50 | 2024-07-08 21:14:51 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
inline void ckmx(int&x,int y){x<y&&(x=y);}
const int N=1e6+5,O=1e9;
int n,m,t,a[N],b[N];
int Sa[N],La[N],Ra[N],Sb[N],Lb[N],Rb[N],P[N];
inline void rd(int a[],int n,int S[],int L[],int R[]){
for(int i=1;i<=n;i++)scanf("%d",&a[i]);
L[0]=0;R[0]=n+1;
for(int i=1,c=0;i<=n;i++)if(a[i]==1)L[++c]=i;
for(int i=n,c=0;i>=1;i--)if(a[i]==3)R[++c]=i;
for(int i=1;i<=n;i++)S[i]=S[i-1]+(a[i]==2);
}
const int S=N<<3;
int M;
struct ZKW{
int tr[S];
inline void upd(int p,int k){tr[p+=M]=k;while(p>>=1)tr[p]=max(tr[p<<1],tr[p<<1|1]);}
inline int qry(int l,int r){
int res=-O;l+=M-1;r+=M+1;
for(;l^r^1;l>>=1,r>>=1){
if(~l&1)ckmx(res,tr[l^1]);
if(r&1)ckmx(res,tr[r^1]);
}
return res;
}
}T1,T2;
inline void bld(int n){for(M=1;M<=n;M<<=1);for(int i=1;i<M+M;i++)T1.tr[i]=T2.tr[i]=-O;}
inline void solve(){
scanf("%d%d",&n,&m);t=max(n,m);
rd(a,n,Sa,La,Ra);rd(b,m,Sb,Lb,Rb);
int c1a=0,c3a=0,c1b=0,c3b=0;
for(int i=1;i<=n;i++){c1a+=a[i]==1;c3a+=a[i]==3;}
for(int i=1;i<=m;i++){c1b+=b[i]==1;c3b+=b[i]==3;}
int c1=min(c1a,c1b),c3=min(c3a,c3b);
bld(t+t+1);
for(int j=0;j<=c3;j++){
P[j]=Sa[Ra[j]-1]-Sb[Rb[j]-1]+t+1;
T1.upd(P[j],j+Sa[Ra[j]-1]);
T2.upd(P[j],j+Sb[Rb[j]-1]);
}
int ans=0;
for(int i=0,j=c3;i<=c1;i++){
for(;~j&&(Ra[j]<La[i]||Rb[j]<Lb[i]);j--){T1.upd(P[j],-O);T2.upd(P[j],-O);}
int res=-O,Pi=Sa[La[i]]-Sb[Lb[i]]+t+1;
ckmx(ans,T1.qry(1,Pi)+i-Sa[La[i]]);
ckmx(ans,T2.qry(Pi,t+t+1)+i-Sb[Lb[i]]);
}
printf("%d\n",ans);
}
int main(){
int T;scanf("%d",&T);
while(T--)solve();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 20312kb
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: 113ms
memory: 20224kb
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 2 2 0 1 2 1 1 1 1 6 1 0 1 2 2 3 4 4 1 1 1 0 2 2 3 4 3 1 1 3 2 1 2 1 3 1 1 1 3 1 1 2 3 2 1 3 1 4 1 2 2 1 3 1 1 2 3 1 2 4 4 2 2 1 1 1 2 4 3 2 1 1 2 3 1 2 2 1 5 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 2 2 2 0 0 2 3 1 2 0 4 1 3 1 1 3 1 1 0 1 1 1 1 3 2 2 2 3 3 3 1 2 2 3 2 1 1 3 3 2 3 ...
result:
wrong answer 31st words differ - expected: '4', found: '3'