QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#631025#5466. Permutation CompressionQHhee004WA 27ms7824kbC++172.0kb2024-10-11 21:28:382024-10-11 21:28:38

Judging History

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

  • [2024-10-11 21:28:38]
  • 评测
  • 测评结果:WA
  • 用时:27ms
  • 内存:7824kb
  • [2024-10-11 21:28:38]
  • 提交

answer

#include<iostream>
#include<cmath>
#include<algorithm>
#include<set>
using namespace std;
const int N=2e5+5;
#define lowbit(x) x&-x
typedef pair<int,int> PII;
#define ft first
#define sd second
class Treearry {
	private:
		int bit[N],tot;
	public:
		void set(int n) {
			tot=n;
		}
		void clear() {
			for(int i=1; i<=tot; i++)bit[i]=0;
		}
		void add(int x,int c) {
			while(x<=tot)bit[x]+=c,x+=lowbit(x); 
		} 
		int get(int x) {
			int ans=0;
			while(x>0)ans+=bit[x],x-=lowbit(x);
			return ans;
		}
} B;
int a[N],pos[N],stk[N];
int L[N],R[N];
bool mark[N];
bool cmp(int i,int j) {
	return a[i]>=a[j];
}
void solve() {
	int n,m,K;
	scanf("%d%d%d",&n,&m,&K);
	for(int i=1; i<=n; i++) {
		scanf("%d",&a[i]);
		pos[a[i]]=i;
	}
	for(int i=1; i<=n; i++)
		mark[i]=false;
	bool flag=0;
	for(int i=1,j=1,u; i<=m; i++) {
		scanf("%d",&u);
		while(j<=n&&a[j]!=u)++j;
		mark[j]=true; ++j;
//		printf("i:%d m:%d j:%d n:%d\n",i,m,j,n);
		if(j>n&&i<m) flag=1;
	}
	for(int i=1; i<=n; i++)
		L[i]=R[i]=0;
	int top=0;
	stk[0]=0;
	for(int i=1; i<=n; i++) {
		if(mark[i]) {
			while(top&&a[stk[top]]<a[i])--top;
			stk[++top]=i;
		} else {
			L[i]=stk[lower_bound(stk+1,stk+1+top,i,cmp)-stk-1]+1;
		}
	}
	top=0;
	stk[0]=n+1;
	for(int i=n; i>=1; i--) {
		if(mark[i]) {
			while(top&&a[stk[top]]<a[i])--top;
			stk[++top]=i;
		} else {
			R[i]=stk[lower_bound(stk+1,stk+1+top,i,cmp)-stk-1]-1;
		}
	}
	multiset <int> S;
	for(int i=1,u; i<=K; i++) {
		scanf("%d",&u);
		S.insert(u);
	}
	if(n-K>m||flag) {
		puts("NO");
		return ;
	}
	B.set(n);
	B.clear();
	for(int i=n; i>=1; i--) {
		if(mark[pos[i]])continue;
		int cnt=R[pos[i]]-L[pos[i]]+1-B.get(R[pos[i]])+B.get(L[pos[i]]-1);
		multiset<int>::iterator itr=S.upper_bound(cnt);
		if(itr==S.begin()) {
			puts("NO");
			return ;
		}
		--itr;
		S.erase(itr);
		B.add(pos[i],1);
	}
	puts("YES");
}
int main() {
	int T;scanf("%d",&T);
	while(T--)solve();
	return 0;
}


Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 0
Accepted
time: 1ms
memory: 7796kb

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

result:

ok 100 lines

Test #3:

score: 0
Accepted
time: 1ms
memory: 5728kb

input:

99
6 1 6
1 5 3 4 2 6
1
1 2 1 1 1 6
1 1 1
1
1
1
4 1 3
3 4 1 2
1
1 1 2
2 2 1
2 1
2 1
2
1 1 1
1
1
1
2 1 2
1 2
2
1 2
1 1 1
1
1
1
1 1 1
1
1
1
3 2 2
3 2 1
2 1
1 2
3 3 1
2 3 1
2 3 1
1
6 1 5
3 4 2 5 6 1
3
4 2 1 1 1
6 4 4
1 6 5 2 3 4
1 2 3 4
5 4 4 6
2 1 1
1 2
1
1
6 5 1
2 1 4 5 6 3
2 1 4 6 3
2
6 3 6
5 6 2 1 3...

output:

YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
NO
NO
YES
YES
YES
YES
YES
YES
YES
YES
YES
NO
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
NO
YES
YES
YES
YES
YES
YES
YES
NO
NO
YES
YES
YES
NO
YES
YES
YES
NO
YES
YES
NO
YES
NO
YES
NO
YES
YES
YES
YES
YES
YES
NO
YES
NO
NO
YES
YES
YES
YE...

result:

ok 99 lines

Test #4:

score: 0
Accepted
time: 1ms
memory: 5764kb

input:

98
6 1 6
6 1 4 5 2 3
3
1 2 2 1 1 6
4 3 2
2 3 4 1
2 1 3
3 4
1 1 1
1
1
1
6 1 6
6 4 3 1 2 5
1
3 1 3 1 1 5
1 1 1
1
1
1
6 4 4
3 4 1 2 5 6
3 4 1 2
2 4 3 1
6 5 1
4 5 3 6 1 2
4 5 3 1 2
6
1 1 1
1
1
1
5 1 4
1 3 2 4 5
1
5 3 4 4
6 3 4
1 4 2 3 6 5
1 2 5
5 4 6 5
4 1 3
2 1 4 3
2
1 1 1
1 1 1
1
1
1
6 3 5
5 1 3 6 4 2...

output:

YES
NO
YES
YES
YES
YES
YES
YES
NO
NO
YES
YES
NO
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
NO
YES
YES
YES
NO
YES
YES
YES
NO
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
NO
YES
YES
YES
YES
NO
YES
YES
YES
YES
YES
NO
YES
NO
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
NO
YES
NO
Y...

result:

ok 98 lines

Test #5:

score: -100
Wrong Answer
time: 27ms
memory: 7824kb

input:

60000
1 1 1
1
1
1
1 1 1
1
1
1
3 2 1
2 3 1
2 1
2
3 3 1
1 2 3
1 2 3
1
1 1 1
1
1
1
1 1 1
1
1
1
1 1 1
1
1
1
3 3 2
3 2 1
3 2 1
1 1
2 2 1
2 1
2 1
1
1 1 1
1
1
1
2 2 1
1 2
1 2
1
1 1 1
1
1
1
3 1 3
2 3 1
1
2 3 2
3 3 2
2 3 1
2 3 1
2 1
1 1 1
1
1
1
1 1 1
1
1
1
1 1 1
1
1
1
3 2 3
3 2 1
2 1
1 2 1
3 2 2
1 3 2
3 2
3 ...

output:

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

result:

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