QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#88989#5466. Permutation CompressionSmall_BlackWA 2ms3488kbC++142.7kb2023-03-18 09:22:112023-03-18 09:22:15

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-03-18 09:22:15]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:3488kb
  • [2023-03-18 09:22:11]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define l(x) (x<<1)
#define r(x) (x<<1|1)
#define mpr make_pair
//mt19937_64 ra(time(0) ^ (*new char));
//ios::sync_with_stdio(false);
//cin.tie(0); cout.tie(0);
const int SIZE = 200005;
const int mod = 998244353;
int n, m, K, T;
int a[SIZE], b[SIZE];
int l[SIZE];
bool v[SIZE], used[SIZE];
int st[SIZE], top;
int nx[SIZE], pr[SIZE];
int c[SIZE];

inline int rd(){
	int x = 0, f = 1;
	char ch = getchar();
	while(ch < '0' || ch > '9'){
		if(ch == '-') f = -1;
		ch = getchar();
	}
	while(ch >= '0' && ch <= '9'){
		x = (x<<1) + (x<<3) + (ch^48);
		ch = getchar();
	}
	return x*f;
}

bool cmp(int x, int y){
	return a[x] > a[y];	
}

int lowbit(int x){
	return x & (-x);	
}

void add(int x, int val){
	for(int i = x; i <= n; i+=lowbit(i)) c[i] += val;	
}

int ask(int x){
	int jl = 0;
	for(int i = x; i; i-=lowbit(i)) jl += c[i];
	return jl;
}

int main(){
	T = rd();
	while(T--){
		n = rd(), m = rd(), K = rd();
		for(int i = 1; i <= n; i++) c[i] = 0;
		for(int i = 1; i <= n; i++) a[i] = rd(), v[i] = 1, add(i, 1);
		for(int i = 1; i <= m; i++) b[i] = rd(), v[b[i]] = 0;
		for(int i = 1; i <= K; i++) l[i] = rd(), used[i] = 0;
		used[0] = used[n+1] = 0;
		sort(l+1, l+K+1); top = 0;
		for(int i = 1; i <= n; i++){
			while(top && a[st[top]] < a[i]) nx[st[top]] = i, top--;
			st[++top] = i;
		}
		while(top) nx[st[top]] = n+1, top--;
		for(int i = n; i >= 1; i--){
			while(top && a[st[top]] < a[i]) pr[st[top]] = i, top--;
			st[++top] = i;
		}
		while(top) pr[st[top]] = 0, top--;
		for(int i = 1; i <= n; i++){
			if(v[a[i]]) st[++top] = i;
			v[a[i]] = 0;
		}
		v[0] = v[n+1] = 0;
		sort(st+1, st+top+1, cmp);
//		for(int i = 1; i <= top; i++) printf("%d ", st[i]);
//		puts("");
		bool ans = 1; 
		for(int i = 1; i <= top; i++){
			int prr = pr[st[i]], nxx = nx[st[i]];
			while(v[prr]) prr = pr[prr];
			while(v[nxx]) nxx = nx[nxx];
			prr++, nxx--;
//			cout << prr << " " << nxx << endl;
			int x = ask(nxx) - (prr==1?0:ask(prr-1)), jl = 0;
//			cout << x << endl;
			for(int j = K; j >= 1; j--){
				if(l[j] > x || used[j]) continue;
				jl = j; break;
			}
			if(jl == 0){
				ans = 0;
				break;
			}
			used[jl] = 1; v[st[i]] = 1; add(st[i], -1);
		}
		if(ans == 0){
			printf("NO\n");
			continue;
		}
		int now = 1;
		for(int i = 1; i <= n; i++){
			if(!v[i]){
				if(a[i] == b[now]) now++;
				else{
					ans = 0;
					break;
				}
			}
		}
		if(ans) printf("YES\n");
		else printf("NO\n");
	}
	return 0;
}
/*
2
8 3 8
8 3 1 7 2 5 4 6
8 7 2
4 4 2 2 1 6 6 6
8 4 7
5 2 6 8 3 4 1 7
6 8 1 7
3 2 2 1 5 5 5


*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 3488kb

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: 0ms
memory: 3396kb

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

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

result:

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