QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#245602#5466. Permutation Compressionjoelgun14WA 1ms3468kbC++141.4kb2023-11-10 05:10:322023-11-10 05:10:33

Judging History

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

  • [2023-11-10 05:10:33]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3468kb
  • [2023-11-10 05:10:32]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
const int N = 2e5+5;
const int inf = 1e9;
int n,m,k,a[N],pos[N],b[N],l[N],need[N];
bool del[N];
int c[N];
int lowbit(int x) {return x&-x;}
void add(int x,int k)
{
    while(x<=n)
    {
        c[x]+=k;
        x+=lowbit(x);
    }
}
int query(int x)
{
    int ans=0;
    while(x)
    {
        ans+=c[x];
        x-=lowbit(x);
    }
    return ans;
}
int query(int x,int y) {return query(y)-query(x-1);}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t;cin>>t;
    while(t--)
    {
        cin>>n>>m>>k;
        for(int i=1;i<=n;i++) cin>>a[i],pos[a[i]]=i;
        for(int i=1;i<=m;i++) cin>>b[i];
        for(int i=1;i<=k;i++) cin>>l[i];    
        if(n-m>k)
        {
            cout<<"NO"<<'\n';
            continue;
        }
        sort(l+1,l+k+1);
        for(int i=1;i<=n;i++) c[i]=0,del[i]=1;
        for(int i=1;i<=m;i++) del[b[i]]=0;
		set<int> s;
		s.insert(0),s.insert(n+1);
        int p=0;
        for(int i=n;i;i--)
            if(del[i])
            {
				auto it=s.lower_bound(pos[i]);
        		int l=*(prev(it)),r=*it;
				need[++p]=r-l-1-query(l+1,r-1);
                add(pos[i],1);
            }
			else s.insert(pos[i]);
		bool ok=1;
		sort(need+1,need+p+1);
		for(int i=1;i<=p;i++)
			if(need[i]<l[i]) ok=0;
        cout<<(ok?"YES":"NO")<<'\n';
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3460kb

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

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

result:

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