QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#136711#238. Distinct Valuessalvator_noster#100 ✓269ms58352kbC++172.0kb2023-08-09 10:21:352023-08-09 10:21:48

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-08-09 10:21:48]
  • 评测
  • 测评结果:100
  • 用时:269ms
  • 内存:58352kb
  • [2023-08-09 10:21:35]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

const int SIZE = 1000000 + 5;

struct PQ {
	priority_queue<int, vector<int>, greater<int> > pq1, pq2;

	void upd(void) {
		while (!pq1.empty() && !pq2.empty() && pq2.top() == pq1.top()) {
			pq2.pop();
			pq1.pop();
		}
		return;
	}

	void clear(void) {
		while (!pq1.empty()) {
			pq1.pop();
		}
		while (!pq2.empty()) {
			pq2.pop();
		}
		return;
	}

	void push(int num) {
		pq1.push(num);
		return;
	}

	void del(int num) {
		pq2.push(num);
		return;
	}

	int empty(void) {
		upd();
		return pq1.empty();
	}

	int top(void) {
		upd();
		return pq1.top();
	}
};

PQ pq1, pq2;

int getInt(void) {
	int ch = getchar(), res = 0;
	while (!isdigit(ch)) {
		ch = getchar();
	}
	for (; isdigit(ch); ch = getchar()) {
		res = res * 10 + (ch - '0');
	}
	return res;
}

vector<int> add[SIZE], del[SIZE];
int li[SIZE];

int main(void) {
	int t = getInt();
	while (t--) {
		int n = getInt(), m = getInt();
		for (int i = 1; i <= m; ++i) {
			int l = getInt(), r = getInt();
			add[l].push_back(l);
			del[r + 1].push_back(l);
		}
		for (int i = 1; i <= n + 1; ++i) {
			pq2.push(i);
		}
		int cur = -1;
		for (int i = 1; i <= n; ++i) {
			for (int num : add[i]) {
				pq1.push(num);
			}
			for (int num : del[i]) {
				pq1.del(num);
			}
			if (!pq1.empty()) {
				int bnd = pq1.top();
				// printf("i = %d, bnd = %d\n", i, bnd);
				if (cur != -1) {
					for (int j = cur; j < bnd; ++j) {
						pq2.push(li[j]);
					}
				}
				cur = bnd;
				li[i] = pq2.top();
			} else {
				if (cur != -1) {
					for (int j = cur; j < i; ++j) {
						pq2.push(li[j]);
					}
				}
				cur = -1;
				li[i] = 1;
			}
			if (cur != -1) {
				pq2.del(li[i]);
			}
		}
		for (int i = 1; i <= n; ++i) {
			printf("%d%c", li[i], " \n"[i == n]);
		}

		for (int i = 1; i <= n + 1; ++i) {
			add[i].clear();
			del[i].clear();
		}
		pq1.clear(), pq2.clear();
	}
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 269ms
memory: 58352kb

input:

11116
10 2
5 5
5 6
10 1
7 10
10 1
2 6
10 1
2 5
10 1
6 7
10 2
8 9
7 10
10 2
1 4
6 10
10 4
8 8
10 10
3 6
1 5
10 3
8 8
10 10
8 10
10 4
6 10
1 5
2 6
1 2
10 3
4 4
4 8
4 8
10 4
1 5
1 2
5 5
2 4
10 4
2 5
9 10
6 7
2 4
10 1
5 6
10 4
10 10
8 10
2 5
10 10
10 1
1 2
10 4
7 8
5 6
7 9
10 10
10 4
3 7
6 6
8 10
3 4
10...

output:

1 1 1 1 1 2 1 1 1 1
1 1 1 1 1 1 1 2 3 4
1 1 2 3 4 5 1 1 1 1
1 1 2 3 4 1 1 1 1 1
1 1 1 1 1 1 2 1 1 1
1 1 1 1 1 1 1 2 3 4
1 2 3 4 1 1 2 3 4 5
1 2 3 4 5 1 1 1 1 1
1 1 1 1 1 1 1 1 2 3
1 2 3 4 5 1 2 3 4 5
1 1 1 1 2 3 4 5 1 1
1 2 3 4 5 1 1 1 1 1
1 1 2 3 4 1 2 1 1 2
1 1 1 1 1 2 1 1 1 1
1 1 2 3 4 1 1 1 2 3
...

result:

ok 11116 lines