QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#120580 | #5466. Permutation Compression | A_zjzj | WA | 1ms | 15240kb | C++14 | 1.6kb | 2023-07-06 22:07:36 | 2023-07-06 22:07:38 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const int N=2e5+10;
int T,n,m,k,a[N],p[N],del[N],len[N];
int top,stk[N],t[N],L[N],R[N];
int c[N];
void add(int x,int y){
for(;x<=n;x+=x&-x)c[x]+=y;
}
int get(int x){
int y=0;
for(;x;x^=x&-x)y+=c[x];
return y;
}
vector<int>o[N];
bool get(){
scanf("%d%d%d",&n,&m,&k);
for(int i=1;i<=n;i++)scanf("%d",&a[i]);
for(int i=1;i<=m;i++)scanf("%d",&p[i]),del[p[i]]=1;
for(int i=1;i<=k;i++)scanf("%d",&len[i]);
if(k<m)return 0;
stk[top=0]=0;
for(int i=1;i<=n;i++){
if(del[i]){
int l=0,r=top+1,mid;
for(;l+1<r;){
mid=(l+r)>>1;
if(a[stk[mid]]>a[i])l=mid;
else r=mid;
}
L[i]=stk[l];
}
else{
for(;top&&a[stk[top]]<a[i];top--);
stk[++top]=i;
}
}
stk[top=0]=n+1;
for(int i=n;i>=1;i--){
if(del[i]){
int l=0,r=top+1,mid;
for(;l+1<r;){
mid=(l+r)>>1;
if(a[stk[mid]]>a[i])l=mid;
else r=mid;
}
R[i]=stk[l];
}
else{
for(;top&&a[stk[top]]<a[i];top--);
stk[++top]=i;
}
}
for(int i=1;i<=m;i++){
o[L[p[i]]].push_back(-i);
o[R[p[i]]-1].push_back(i);
}
for(int i=1;i<=n;i++){
add(a[i],1);
for(int x:o[i]){
if(x>0)t[x]+=get(a[p[x]]);
else t[-x]-=get(a[p[-x]]);
}
}
sort(t+1,t+1+m),sort(len+1,len+1+k);
for(int i=k,j=m,x=0;j>=1;){
if(i<1)return 0;
if(t[j]>=len[i]-x)i--,j--,x=0;
else i--,x++;
}
return 1;
}
void clear(){
for(int i=1;i<=m;i++)t[i]=0;
for(int i=1;i<=n;i++)del[i]=c[i]=0;
for(int i=1;i<=n;i++)o[i].clear();
}
int main(){
for(scanf("%d",&T);T--;clear())puts(get()?"YES":"NO");
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 15240kb
input:
3 5 2 3 5 1 3 2 4 5 2 1 2 4 5 5 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 3 2 2 3 1 2 3 2 2 3
output:
YES YES NO
result:
ok 3 lines
Test #2:
score: -100
Wrong Answer
time: 1ms
memory: 14756kb
input:
100 2 1 2 2 1 2 1 1 2 1 2 1 2 1 2 2 2 1 1 1 2 1 2 6 1 5 3 4 2 5 6 1 3 5 2 1 1 1 6 1 6 2 1 3 6 4 5 1 4 1 2 2 1 4 3 3 2 2 1 3 2 1 3 2 2 1 1 1 1 1 1 1 1 1 1 1 1 2 1 2 2 1 2 1 2 4 4 3 2 1 3 4 2 1 3 4 4 3 1 1 1 1 1 1 1 6 5 1 6 2 5 4 3 1 6 2 4 3 1 4 1 1 1 1 1 1 6 5 3 3 6 1 4 5 2 3 6 1 4 2 3 3 4 4 3 4 3 4 ...
output:
YES YES NO YES YES NO YES YES YES NO YES NO YES NO YES NO YES YES YES NO NO YES NO YES NO YES NO NO YES NO NO YES NO YES YES YES NO YES NO YES NO YES YES NO NO YES YES YES YES NO YES YES NO YES YES YES YES NO NO YES NO YES YES YES YES YES YES YES YES NO YES NO YES NO NO YES YES NO NO YES YES YES NO ...
result:
wrong answer 3rd lines differ - expected: 'YES', found: 'NO'