QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#138558#5466. Permutation Compressionammardab3an#WA 1ms3608kbC++172.8kb2023-08-11 22:54:112023-08-11 22:54:15

Judging History

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

  • [2023-08-11 22:54:15]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3608kb
  • [2023-08-11 22:54:11]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

using ll = long long;

vector<int> st, st1;
vector<int> a, b, c;

void build(int v, int l, int r) {
	if (l == r) {
		st[v] = a[l];
		st1[v] = 1;
	}
	else {
		int mid = (l + r) / 2;
		build(2 * v, l, mid);
		build(2 * v + 1, mid + 1, r);
		st[v] = max(st[2 * v], st[2 * v + 1]);
		st1[v] = st1[2 * v] + st1[2 * v + 1];
	}
}

int query(int v, int l, int r, int tl, int tr) {
	if (tl > tr) return 0;
	if (l == tl && r == tr) return st[v];
	int mid = (l + r) / 2;
	int f = query(2 * v, l, mid, tl, min(mid, tr));
	int s = query(2 * v + 1, mid + 1, r, max(mid + 1, tl), tr);
	return max(f, s);
}

int query1(int v, int l, int r, int tl, int tr) {
	if (tl > tr) return 0;
	if (l == tl && r == tr) return st1[v];
	int mid = (l + r) / 2;
	int f = query1(2 * v, l, mid, tl, min(mid, tr));
	int s = query1(2 * v + 1, mid + 1, r, max(mid + 1, tl), tr);
	return f + s;
}

void del(int v, int l, int r, int idx) {
	if (l == r) {
		st[v] = 0;
		st1[v] = 0;
		return;
	}
	int mid = (l + r) / 2;
	if (idx <= mid) del(2 * v, l, mid, idx);
	else del(2 * v + 1, mid + 1, r, idx);
	st[v] = max(st[2 * v], st[2 * v + 1]);
	st1[v] = st1[2 * v] + st1[2 * v + 1];
}

int main() {

	ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);

	int t;
	cin >> t;

	while (t--) {

		int n, m, k;
		cin >> n >> m >> k;

		a.clear();
		a.resize(n);
		b.clear();
		b.resize(m);
		c.clear();
		c.resize(k);

		for (int& x : a) cin >> x;
		for (int& x : b) cin >> x;
		for (int& x : c) cin >> x;

		sort(c.begin(), c.end());

		set<int> temp(b.begin(), b.end());
		vector<int> d;

		for (int i = 1; i <= n; i++) {
			if (!temp.count(i)) d.push_back(i);
		}
		sort(d.begin(), d.end(), greater<int>());

		bool ok = 1;

		st.clear(); st1.clear();
		st.resize(n * 4 + 10);
		st1 = st;
		build(1, 0, n - 1);

		multiset<int> cc(c.begin(), c.end());

		vector<int> idx(n + 1, 0);
		vector<ll>need;
		for (int i = 0; i < n; i++) idx[a[i]] = i;
		for (int x : d) {

			bool ok1 = 0;

			int nxt = idx[x], prev = idx[x];
			int l = idx[x], r = n - 1;
			while (l <= r) {
				int mid = (l + r) / 2;
				if (query(1, 0, n - 1, idx[x], mid) <= x) {
					nxt = mid;
					l = mid + 1;
				}
				else r = mid - 1;
			}

			l = 0, r = idx[x];
			while (l <= r) {
				int mid = (l + r) / 2;
				if (query(1, 0, n - 1, mid, idx[x]) <= x) {
					prev = mid;
					r = mid - 1;
				}
				else l = mid + 1;
			}

			int len = query1(1, 0, n - 1, prev, nxt);

			need.emplace_back(len);
			del(1, 0, n - 1, idx[x]);

		}
		ok = 1;
		sort(need.begin(), need.end());
		for (int i = 0, j = 0; i < need.size(); i++) {
			if (j == c.size() || c[j] > need[i]) {
				ok = 0;
				break;
			}
		}

		if (ok) cout << "YES\n";
		else cout << "NO\n";

	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 1ms
memory: 3608kb

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

result:

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