QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#75847#5466. Permutation CompressionXKErrorWA 3ms5564kbC++141.3kb2023-02-06 13:05:382023-02-06 13:05:42

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-02-06 13:05:42]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:5564kb
  • [2023-02-06 13:05:38]
  • 提交

answer

#include <bits/stdc++.h>

#define maxn 200005

using namespace std;

int n, m, k;
int a[maxn];
int b[maxn];

int p[maxn];
int q[maxn];

multiset<int> s, t;

int ft[maxn];

void add(int x, int k) {
	for (; x <= n; x += x & -x) ft[x] += k;
}

int qry(int l, int r) {
	int res = 0;
	for (int x = l - 1; x; x -= x & -x) res -= ft[x];
	for (int x = r; x; x -= x & -x) res += ft[x];
	return res;
}

int main() {
	int T;
	scanf("%d", &T);
	while (T--) {
		scanf("%d%d%d", &n, &m, &k);
		for (int i = 1; i <= n; i++) ft[i] = p[i] = q[i] = 0;
		for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
		for (int i = 1; i <= n; i++) p[a[i]] = i;
		for (int i = 1; i <= m; i++) scanf("%d", &b[i]);
		for (int i = 1; i <= m; i++) q[b[i]] = i;
		
		for (int i = 1; i <= n; i++) add(i, 1);
		s.clear();
		t.clear();
		t.insert(0);
		t.insert(n + 1);
		
		while (k--) {
			int x;
			scanf("%d", &x);
			s.insert(x);
		}
		for (int i = n; i; i--) {
			if (q[i]) t.insert(p[i]);
			else {
				int r = *t.lower_bound(p[i]);
				int l = *--t.lower_bound(p[i]);
				int len = qry(l + 1, r - 1);
				auto tmp = s.upper_bound(len);
//				cout<<*tmp<<"!"<<endl;
				if (tmp == s.begin()) {
					puts("NO");
					goto B;
				}
				s.erase(--tmp);
				add(p[i], -1);
			}
		}
		puts("YES");
		B:;
	}
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 3ms
memory: 5516kb

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: 3ms
memory: 5564kb

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'