QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#120576#5466. Permutation CompressionA_zjzjWA 2ms14636kbC++141.6kb2023-07-06 22:00:372023-07-06 22:00:38

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-06 22:00:38]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:14636kb
  • [2023-07-06 22:00:37]
  • 提交

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+k),sort(len+1,len+1+m);
	for(int i=m,j=k;i>=1;i--,j--)if(t[j]<len[i])return 0;
	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;
}

详细

Test #1:

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

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: 2ms
memory: 14636kb

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

result:

wrong answer 2nd lines differ - expected: 'YES', found: 'NO'