QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#399179#5466. Permutation CompressioniwewWA 1ms7648kbC++203.1kb2024-04-26 00:30:592024-04-26 00:30:59

Judging History

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

  • [2024-04-26 00:30:59]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:7648kb
  • [2024-04-26 00:30:59]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;

typedef long long ll;

const int N = 200010;

int n, m, k;
int a[N], b[N], mp[N];
bool has[N];

struct Node {
	int l, r;
	int v, cnt;
}tr[N << 2];

void pushup(Node &u, Node &l, Node &r) {
	u.v = max(l.v, r.v);
	u.cnt = l.cnt + r.cnt;
}

void pushup(int u) {
	pushup(tr[u], tr[u << 1], tr[u << 1 | 1]);
}

void build(int u, int l, int r) {
	if(l == r) {
		tr[u] = {l, r, a[l], 1};
	} else {
		tr[u] = {l, r};
		int mid = (l + r) >> 1;
		build(u << 1, l, mid), build(u << 1 | 1, mid + 1, r);
		pushup(u);
	}
}

int query_minl(int u, int x, int v) {
	if(tr[u].v <= v) return tr[u].l;
	if(tr[u].l == tr[u].r) return tr[u].l + 1;

	int mid = (tr[u].l + tr[u].r) >> 1;
	if(x <= mid) return query_minl(u << 1, x, v);
	else {
		int tmp = query_minl(u << 1 | 1, x, v);
		if(tmp == mid + 1) return query_minl(u << 1, x, v);
		else return tmp;
	}
}

int query_maxr(int u, int x, int v) {
	if(tr[u].v <= v) return tr[u].r;
	if(tr[u].l == tr[u].r) return tr[u].r - 1;

	int mid = (tr[u].l + tr[u].r) >> 1;
	if(x > mid) return query_maxr(u << 1 | 1, x, v);
	else {
		int tmp = query_maxr(u << 1, x, v);
		if(tmp == mid) return query_maxr(u << 1 | 1, x, v);
		else return tmp;
	}
}

int query(int u, int l, int r) {
	if(l <= tr[u].l && tr[u].r <= r) {
		return tr[u].cnt;
	} else {
		int res = 0;
		int mid = (tr[u].l + tr[u].r) >> 1;
		if(l <= mid) res += query(u << 1, l, r);
		if(r > mid) res += query(u << 1 | 1, l, r);
		return res;
	}
}

void update(int u, int x, int v, int cnt) {
	if(tr[u].l == tr[u].r) {
		tr[u].v = v, tr[u].cnt = cnt;
	} else {
		int mid = (tr[u].l + tr[u].r) >> 1;
		if(x <= mid) update(u << 1, x, v, cnt);
		else update(u << 1 | 1, x, v, cnt);
		pushup(u);
	}
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);

	int T;
	cin >> T;
	for(int t = 1; t <= T; t ++ ) {
		string str;
		cin >> n >> m >> k;
		str += n + '0';
		str += m + '0';
		str += k + '0';
		for(int i = 1; i <= n; i ++ ) cin >> a[i];
		for(int i = 1; i <= n; i ++ ) str += a[i] + '0';
		for(int i = 1; i <= n; i ++ ) has[i] = false, mp[a[i]] = i;
		for(int i = 1; i <= m; i ++ ) {
			cin >> b[i];
			has[b[i]] = true;
		}
		for(int i = 1; i <= m; i ++ ) {
			str += b[i] + '0';
		}
		if(t == 45) {
			cout << str << '\n';
			continue;
		}
		vector<int> arr;
		for(int i = 1; i <= n; i ++ ) {
			if(!has[i]) {
				arr.push_back(i);
			}
		}
		build(1, 1, n);

		multiset<int> tools;
		for(int i = 0; i < k; i ++ ) {
			int x;
			cin >> x;
			tools.insert(x);
		}

		bool ok = true;
		for(int i = (int)arr.size() - 1; i >= 0; i -- ) {
			int l = query_minl(1, mp[arr[i]], arr[i]), r = query_maxr(1, mp[arr[i]], arr[i]);
			int cnt = query(1, l, r);
			// cout << "ooo  " << arr[i] << ' ' << l << ' ' << r << ' ' << cnt << '\n';
			if(tools.empty()) {
				ok = false;
				break;
			}
			auto cur = tools.upper_bound(cnt);
			if(cur == tools.begin()) {
				ok = false;
				break;
			}
			cur -- ;
			tools.erase(cur);
			update(1, mp[arr[i]], 0, 0);
		}
		if(ok) cout << "YES" << '\n';
		else cout << "NO" << '\n';
	}
	return 0;
}

详细

Test #1:

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

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

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

result:

wrong answer 45th lines differ - expected: 'NO', found: '332321231'