QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#30354#238. Distinct ValuessrfAC ✓327ms9440kbC++908b2022-04-27 14:41:542022-04-28 16:58:29

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-04-28 16:58:29]
  • 评测
  • 测评结果:AC
  • 用时:327ms
  • 内存:9440kb
  • [2022-04-27 14:41:54]
  • 提交

answer

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

inline void read(int &x){
	static char c; x = 0,c = getchar();
	while (!isdigit(c)) c = getchar();
	while (isdigit(c)) x = x * 10 + c - '0',c = getchar();
}

int n;
int l[100005];
int ans[100005],cnt[100005];
set<int>S;
void solve(){
	int i,q,ql,qr;
	read(n),read(q);
	S.clear();
	for (i = 1; i <= n; ++i) cnt[i] = ans[i] = 0,l[i] = i,S.insert(i);
	while (q--) read(ql),read(qr),l[qr] = min(l[qr],ql);
	for (i = n-1; i ; --i) l[i] = min(l[i],l[i+1]);
	
	ans[1] = 1,++cnt[1]; if (cnt[1] == 1) S.erase(1);
	for (i = 2; i <= n; ++i){
		for (int j = l[i-1]; j < l[i]; ++j){
			--cnt[ans[j]];
			if (cnt[ans[j]] == 0) S.insert(ans[j]);
		}
		ans[i] = *S.begin();
		++cnt[ans[i]],S.erase(ans[i]);
	}
	for (i = 1; i <= n; ++i) cout << ans[i] << (i<n?' ':'\n');
	
}

int main(){
	int T; read(T);
	while (T--) solve(); 
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 327ms
memory: 9440kb

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