QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#137074#238. Distinct ValuesAkagi_Ritsuko_219100 ✓249ms7828kbC++202.1kb2023-08-09 19:09:522023-08-09 19:09:56

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 19:09:56]
  • 评测
  • 测评结果:100
  • 用时:249ms
  • 内存:7828kb
  • [2023-08-09 19:09:52]
  • 提交

answer

#include<bits/stdc++.h>
#define rep(i, l, r) for(int i = l; i <= r; i++)
#define per(i, r, l) for(int i = r; i >= l; i--)
#define _rep(i, l, r) for(int i = l; i < r; i++)
#define _per(i, r, l) for(int i = r; i > l; i--)
#define pb push_back
#define po pop_back
#define empb emplace_back
#define emp emplace
#define fir first
#define sec second
using namespace std;

using ldb = long double;
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pil = pair<int, ll>;
using vii = vector<pii>;
using vli = vector<pli>;
using vil = vector<pil>;

struct Seg {
	int l, r;
};

void solve() {
	int n, m, seg0 = 0; cin >> n >> m; 

	vi v(n + 2, 0), nex(n + 2, 0), a(n + 2, 0); 
	Seg s[m + 2], seg[m + 2];
	
	rep(i, 1, m) {
		cin >> s[i].l >> s[i].r; 
	}
	
	sort(s + 1, s + 1 + m, [&](const Seg A, const Seg B) {
		return A.l < B.l; 
	});
	
	seg[++seg0] = (Seg){s[1].l, s[1].r};
	rep(i, 2, m) {
		if (seg[seg0].l == s[i].l) {
			seg[seg0] = {s[i].l, max(seg[seg0].r, s[i].r)};
		} else {
			if (seg[seg0].r < s[i].r) 
			seg[++seg0] = s[i]; 
		}
	}
	
	rep(i, 1, seg0) {
		auto [l, r] = seg[i]; 
		//printf("l = %d, r = %d\n", l, r); 
		rep(j, l, r) {
			if (i != seg0 && j >= seg[i + 1].l) break; 
			nex[j] = r + 1;
		}
	}
	
	//rep(i, 1, n) printf("nex[i] = %d\n", nex[i]); 
	
	priority_queue<pii, vii, greater<pii> > unuse;
	priority_queue<int, vi, greater<int> > use; 
	rep(i, 1, n) unuse.push({1, i});
	
	rep(i, 1, n) {
		if (!nex[i]) a[i] = 1;
		else {
			//注意使用优先队列的时候,size要始终记住
			while (unuse.size() && unuse.top().fir <= i) {
				//<=
				auto [pos, x] = unuse.top();
				//cout << "pos = " << pos << endl; 
				use.push(x); 
				//printf("use.push(x) = %d\n", x);
				unuse.pop(); 
			}
			int x = use.top(); 
			//printf("pos = %d, x = %d\n", i, x);
			use.pop();
			a[i] = x; 
			unuse.emp(nex[i], x);
		}
	}
	
	rep(i, 1, n) cout << a[i] << ' '; cout << '\n';
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int T; cin >> T;
	while (T--) solve();
}

详细

Test #1:

score: 100
Accepted
time: 249ms
memory: 7828kb

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 ...

result:

ok 11116 lines