QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#136648#238. Distinct ValuesBoulevardDust#100 ✓528ms15160kbC++171.2kb2023-08-09 09:42:242023-08-09 09:42:28

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:42:28]
  • 评测
  • 测评结果:100
  • 用时:528ms
  • 内存:15160kb
  • [2023-08-09 09:42:24]
  • 提交

answer

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <set>
#include <vector>
#define mn 100005

using namespace std;

int T, n, m, a[mn], cnt[mn];

struct P {
	int l, r;
	int operator<(const P &p) const { return l < p.l || (l == p.l && r < p.r); }
}b[mn];

vector<int> v[mn];
set<int> sv;
multiset<int> sl;


int main() {
	scanf("%d", &T);
	while(T--) {
		scanf("%d%d", &n, &m);
		for(int i = 1; i <= n; ++i) {
			v[i].clear(), cnt[i] = 0;
		}
		for(int i = 1; i <= m; ++i) {
			scanf("%d%d", &b[i].l, &b[i].r);
			++cnt[b[i].l];
			v[b[i].r].push_back(b[i].l);
		}
		// m + n ?
		sort(b + 1, b + m + 1);
		sv.clear();
		for(int i = 1; i <= n; ++i) {
			sv.insert(i);
		}
		sl.clear();
		int l = 1;
		for(int i = 1; i <= n; ++i) {
			int x = *sv.begin();
			a[i] = x, sv.erase(x);
			for(int j = 0; j < cnt[i]; ++j) {
				sl.insert(i);
			}
			for(int j = 0; j < (int)v[i].size(); ++j) {
				sl.erase(sl.find(v[i][j]));
			}
			while((sl.empty() && l <= i) || (!sl.empty() && l < *sl.begin())) {
				sv.insert(a[l++]);
			}
		}
		for(int i = 1; i <= n; ++i) {
			printf("%d", a[i]);
			if(i != n) printf(" ");
		}
		puts("");
	}
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 528ms
memory: 15160kb

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