QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#136655#238. Distinct Valuessalvator_noster#0 0ms0kbC++171.7kb2023-08-09 09:46:292023-08-09 09:46:31

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 09:46:31]
  • 评测
  • 测评结果:0
  • 用时:0ms
  • 内存:0kb
  • [2023-08-09 09:46:29]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

const int SIZE = 100000 + 5;

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;
}

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);
		}
		set<int> st;
		for (int i = 1; i <= n + 1; ++i) {
			st.insert(i);
		}
		int cur = -1;
		for (int i = 1; i <= n; ++i) {
			for (int num : add[i]) {
				pq1.push(num);
			}
			for (int num : del[i]) {
				pq2.push(num);
			}
			upd();
			if (!pq1.empty()) {
				int bnd = pq1.top();
				if (cur == -1) {
					for (int j = bnd; j < i; ++j) {
						st.erase(li[j]);
					}
				} else {
					for (int j = cur; j < bnd; ++j) {
						st.insert(li[j]);
					}
				}
				cur = bnd;
				li[i] = *st.begin();
			} else {
				for (int j = cur; j < i; ++j) {
					st.insert(li[j]);
				}
				cur = -1;
				li[i] = 1;
			}
			if (cur != -1) {
				st.erase(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();
		}
		clear();
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Time Limit Exceeded

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

result: