QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#603560#5466. Permutation Compressionbessie_goes_mooWA 1ms7668kbC++141.6kb2024-10-01 17:18:112024-10-01 17:18:11

Judging History

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

  • [2024-10-01 17:18:11]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:7668kb
  • [2024-10-01 17:18:11]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
int read(){
    int red=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){ if(ch=='-') f=-f;ch=getchar();}
    while(ch>='0'&&ch<='9') red=red*10+ch-48,ch=getchar();
    return red*f;
}
const int N=2e5+5;
int T,n,m,k,ans,a[N],b[N],c[N],p[N],l[N];
bool vis[N];
multiset<int>S;
multiset<int>::iterator it;
set<int>pos;
set<int>::iterator it2;
int t[N];
void add(int x){
    for(int i=x;i<=n+1;i+=i&-i) t[i]++;
}
int get(int x){
    int ret=0;
    for(int i=x;i;i-=i&-i) ret+=t[i];
    return ret;
}
void clear(){
    for(int i=1;i<=n+1;i++) vis[i]=t[i]=0;
    S.clear();pos.clear();
}
int main(){
    T=read();
    while(T--){
        clear();n=read(),m=read(),k=read();ans=1;
        for(int i=1;i<=n;i++) a[i]=read(),p[a[i]]=i;
        for(int i=1;i<=m;i++) b[i]=read(),vis[b[i]]=1;
        for(int i=1;i<=k;i++) l[i]=read(),S.insert(l[i]);
        for(int i=1;i<=m;i++) if(p[b[i]]<p[b[i-1]]){ans=0;break;}
        if(!ans){puts("NO");continue;}
        sort(l+1,l+1+k);reverse(l+1,l+1+k);c[0]=b[0]=0;
        for(int i=1;i<=n;i++) if(vis[a[i]]) c[++c[0]]=i;
        for(int i=1;i<=n;i++) if(!vis[i]) b[++b[0]]=i;
        m=b[0];reverse(b+1,b+1+m);c[++c[0]]=n+1;
        b[0]=n+1;pos.insert(0);pos.insert(n+1);
        for(int i=1;i<=m;i++){
            for(int j=b[i-1]-1;j>b[i];j--) pos.insert(p[j]);
            int x=b[i];it2=pos.lower_bound(p[x]);
            int r=*it2,l=*--it2,now=get(r)-get(l);
            it=S.lower_bound(r-l-now);
            if(it==S.begin()){ans=0;break;}
            S.erase(--it);
            add(p[x]);
        }
        puts(ans?"YES":"NO");
    }
}

详细

Test #1:

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

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: 7668kb

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
YES
YES
YES
YES
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES
NO
NO
NO
NO
NO
NO
NO
NO
YES
NO
NO
NO
NO
NO
NO
NO
NO
YES
YES
NO
NO
NO
NO
NO
YES
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES
NO
YES
NO
YES
YES
...

result:

wrong answer 7th lines differ - expected: 'YES', found: 'NO'