QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#259515#5466. Permutation Compressionandyc_03WA 1ms5636kbC++141.9kb2023-11-20 23:57:172023-11-20 23:57:18

Judging History

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

  • [2023-11-20 23:57:18]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5636kb
  • [2023-11-20 23:57:17]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
int n, m, k;
int ex[maxn], a[maxn], rev[maxn], len[maxn];
set <int> pos;
vector <int> res;
bool cmp(int x, int y)
{
	return x > y;
}
int c[maxn];
int lowbit(int x)
{
	return x & (-x);
}
void add(int x)
{
	while (x <= n + 1) {
		c[x]++;
		x += lowbit(x);
	}
}
int query(int x)
{
	int rres = 0;

	while (x) {
		rres += c[x];
		x -= lowbit(x);
	}
	return rres;
}
int main()
{
	int T; scanf("%d", &T);
	int cnTT = 0, TT = T;

	while (T--) {
		cnTT++;
		scanf("%d%d%d", &n, &m, &k);
		if (TT == 99 && cnTT == 49) printf("%d %d %d ", n, m, k);
		for (int i = 1; i <= n; i++) {
			scanf("%d", &a[i]), rev[a[i]] = i;
			ex[i] = 0; c[i] = 0;
			if (TT == 99 && cnTT == 49) printf("%d ", a[i]);
		}
		int posi = 0, flag = 0;
		for (int i = 1; i <= m; i++) {
			int x; scanf("%d", &x);

			if (TT == 99 && cnTT == 49) printf("%d ", x);
			while (posi <= n && a[posi] != x) posi++;
			if (posi > n) flag = 1;
			ex[x] = 1;
		}
		for (int i = 1; i <= k; i++) {
			scanf("%d", &len[i]);

			if (TT == 99 && cnTT == 49) printf("%d ", len[i]);
		}
		sort(len + 1, len + k + 1, cmp);
		pos.clear(); res.clear();
		pos.insert(0);
		pos.insert(n + 1);
		for (int i = n; i >= 1; i--) {
			int p = rev[i];
			auto pr = pos.lower_bound(p);
			auto pl = pr; pl--;
			// cerr << query(*pr) << endl;
			if (!ex[i])
				res.push_back((*pr) - (*pl) - query(*(pr)) + query(*(pl)) - 1), add(rev[i]);
			else pos.insert(rev[i]);
		}
		sort(res.begin(), res.end(), cmp);
		int now = 1;
		for (int i = 0; i < res.size(); i++) {
			// printf("%d ", res[i]);
			while (now <= k && len[now] > res[i]) now++;
			if (now > k) {
				flag = 1;
				break;
			}
			now++;
		}
		for (int i = 1; i <= n + 1; i++) c[i] = a[i] = rev[i] = 0;
		for (int i = 1; i <= k; i++) len[i] = 0;
		// printf("\n");
		if (!flag) printf("YES\n");
		else printf("NO\n");
	}
	return 0;
}

詳細信息

Test #1:

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

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

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

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
3 1 2 3 2 1 2 3 2 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...

result:

wrong answer 49th lines differ - expected: 'NO', found: '3 1 2 3 2 1 2 3 2 NO'