QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#735494 | #9574. Strips | UESTC_NLNS# | WA | 18ms | 13968kb | C++14 | 2.0kb | 2024-11-11 20:21:58 | 2024-11-11 20:21:59 |
Judging History
answer
#include<bits/stdc++.h>
#define INF 0x3f3f3f3f
using namespace std;
const int N=400005;
int t,n,m,k,w,la;
int a[N],b[N],c[N],d[N],f[N],st[N],top,q[N],g[N];
vector<int>Ans;
long long ans;
int solve(int l,int r){
if(l+1==r)return 0;
int num=0;
c[++num]=l+1;if(c[num]+k-1>=r)--num;c[++num]=r-k;if(c[num]<=l)--num;top=0;int mx=0;
while(la<=n&&a[la]<=r){
if(a[la]+k<=r)c[++num]=a[la];st[++top]=a[la];
if(a[la]-k>l)c[++num]=a[la]-k;mx=max(mx,a[la]);
++la;
}if(mx==0)return 0;
// for(int i=1;i<=num;++i)cerr<<c[i]<<":";cerr<<"\n";
for(int i=1;i<=num;++i)c[i]=c[i]+k-1;
sort(c+1,c+num+1);int nm=0;
for(int i=1;i<=num;++i)if(c[i]!=c[i-1])d[++nm]=c[i];
num=nm;
for(int i=1;i<=num;++i)f[i]=INF,g[i]=-1;int id=-1;
// for(int i=1;i<=num;++i)cerr<<d[i]<<" ";cerr<<"??\n";
int p=0;d[0]=-INF;f[0]=0;st[0]=-INF;
int L=1,R=1,bj=0;q[1]=0;int as=INF;
for(int i=1;i<=nm;++i){
int tmp=d[i]-k+1;
while(p+1<=top&&st[p+1]<tmp)++p;
// cerr<<p<<" "<<st[p]<<"\n";
if(d[bj+1]<tmp&&bj+1<=nm){
// cerr<<d[bj+1]<<"bj\n";
while(L<=R&&f[bj+1]<=f[q[R]])--R;
q[++R]=bj+1;
++bj;
}
while(L<=R&&d[q[L]]<st[p])++L;
if(L<=R)f[i]=f[q[L]]+1,g[i]=q[L];
if(d[i]>=mx){
if(f[i]<as)as=f[i],id=i;
}
}
if(as==INF)return as;
int x=id;
while(x)Ans.push_back(d[x]-k+1),x=g[x];
return as;
}
signed main(){
cin.tie(0), cout.tie(0), ios::sync_with_stdio(0);
cin>>t;
while(t--){
cin>>n>>m>>k>>w;ans=0;Ans.clear();
for(int i=1;i<=n;++i)cin>>a[i];
for(int i=1;i<=m;++i)cin>>b[i];la=1;
sort(b+1,b+m+1);sort(a+1,a+n+1);
for(int i=1;i<=m;++i)ans+=solve(b[i-1],b[i]);
ans+=solve(b[m],w+1);
if(ans<INF){
cout<<ans<<"\n";
sort(Ans.begin(),Ans.end());
for(int x:Ans)cout<<x<<" ";cout<<"\n";
}
else cout<<"-1\n";
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 13968kb
input:
4 5 2 3 16 7 11 2 9 14 13 5 3 2 4 11 6 10 2 1 11 2 1 2 6 1 5 3 2 1 2 6 1 5 2
output:
4 1 6 9 14 -1 2 1 4 -1
result:
ok ok 4 cases (4 test cases)
Test #2:
score: -100
Wrong Answer
time: 18ms
memory: 13860kb
input:
11000 3 8 2 53 32 3 33 35 19 38 20 1 30 10 6 7 10 1 42 3 14 4 36 28 40 22 17 20 12 41 27 7 1 19 13 9 6 6 13 78 55 76 53 32 54 58 62 45 21 4 7 61 8 7 3 68 9 26 54 31 22 3 38 65 34 16 58 47 52 29 53 5 8 4 33 33 5 30 6 15 27 12 9 28 19 2 13 10 6 1 2 48 8 12 48 1 41 31 40 7 6 7 61 20 19 30 52 49 17 40 3...
output:
2 2 32 7 3 4 14 22 28 36 40 3 22 46 66 8 3 9 22 26 30 38 54 65 3 3 14 30 6 1 8 12 31 41 47 4 17 27 39 47 2 52 67 1 27 1 9 1 62 5 24 33 43 48 60 2 4 31 3 11 20 29 3 3 16 33 3 25 30 42 3 3 17 60 -1 2 54 66 3 50 59 65 3 50 62 78 1 81 4 1 11 16 23 5 3 7 17 36 49 2 1 45 2 7 25 1 ...
result:
wrong answer Participant didn't find a solution but the jury found one. (test case 18)