QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#249106#5466. Permutation Compressionjoelgun14WA 1ms3680kbC++142.8kb2023-11-12 00:54:532023-11-12 00:54:55

Judging History

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

  • [2023-11-12 00:54:55]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3680kb
  • [2023-11-12 00:54:53]
  • 提交

answer

#include <bits/stdc++.h>
#define LL long long
#define fi first
#define se second
#define mp make_pair
using namespace std;
LL psum[200005];
LL n,m,k;
void ins(LL x)
{
	for(LL a=x;a<=n;a+=(a&-a))psum[a]++;
}
LL query(LL x)
{
	LL tot=0;
	for(LL a=x;a>=1;a-=(a&-a))tot+=psum[a];
	return tot;
}
LL query2(LL x,LL y)
{
	return query(y)-query(x-1);
}
void solve(){
	
	scanf("%lld %lld %lld",&n,&m,&k);
	for(LL a=1;a<=n;a++)psum[a]=0;
	LL pos[n+5],arr[n+5],brr[m+5],l[k+5];
	bool temp[n+5];
	memset(temp,0,sizeof(temp));
	for(LL a=1;a<=n;a++)
	{
		scanf("%lld",&arr[a]);
		pos[arr[a]]=a;
	}
	for(LL a=1;a<=m;a++)
	{
		scanf("%lld",&brr[a]);
		temp[brr[a]]=1;
	}
	vector<LL>ada;
	multiset<LL>line;
	set<LL>isi;
	for(LL a=1;a<=k;a++){
		scanf("%lld",&l[a]);
		line.insert(l[a]);
	}
	if(n-m>k){
		printf("NO\n");
		return;
	}
	LL left=1;
	for(LL a=1;a<=m;a++)
	{
		while(true){
			if(left==n+1){
				printf("NO\n");
				return;
			}
			if(arr[left]==brr[a]){
				left++;
				break;
			}
			left++;
			
		}
		
	}
	
	for(LL a=n;a>=1;a--){
//		printf("a=%lld\n",a);
//		printf("line : ");
//		for(LL v:line)cout<<v;
//		cout<<endl;
//		printf("isi :");
//		for(LL v:isi)cout<<v;
//		cout<<endl;
		if(temp[a])isi.insert(pos[a]);
		else{
			if(line.size()==0){
					printf("NO\n");
					return;
				}
			if(isi.size()==0){
			//	printf("SATU");
				auto atas=line.upper_bound(a);
				if(atas==line.begin())
				{
					printf("NO\n");
					return;
				}
				
				line.erase(line.find(*(--atas)));
				ins(pos[a]);
			//	isi.insert(pos[a]);
				continue;
			}
			auto atas = isi.lower_bound(pos[a]);
			if(atas==isi.end()){
		//		printf("DUA\n");
				LL jeje=*(--atas);
				LL banyak=n-jeje;
				banyak-=query2(jeje,n);
				auto koko=line.upper_bound(banyak);
				if(koko==line.begin()){
					printf("NO\n");
					return;
				}
				--koko;
				line.erase(line.find(*koko));
			}
			else if(atas==isi.begin()){
			//	printf("TIGA\n");
				LL banyak=*atas;
				banyak--;
				banyak-=query2(1,banyak);
				auto koko=line.upper_bound(banyak);
				if(koko==line.begin()){
					printf("NO\n");
					return;
				}
				--koko;
				line.erase(line.find(*koko));
			}
			else
			{
				
			//	printf("EMPAT\n");
				LL banyak=*atas;
			//	printf("banyak=%lld\n",banyak);
				LL astaga=*(--atas);
			//	printf("astaga=%lld\n",astaga);
				banyak =banyak-astaga-1;
				banyak-=query2(banyak,astaga);
			//	printf("Banyak=%lld\n",banyak);
				auto koko=line.upper_bound(banyak);
				if(koko==line.begin()){
					printf("NO\n");
					return;
				}
				--koko;
				line.erase(line.find(*koko));
			}
			ins(pos[a]);
			
		}
	}
	printf("YES\n");
}
int main()
{
	LL tc;
	scanf("%lld",&tc);
	while(tc--)
	{
		solve();
		
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

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: -100
Wrong Answer
time: 1ms
memory: 3628kb

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

result:

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