QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#303906 | #238. Distinct Values | teraqqq | 100 ✓ | 447ms | 17612kb | C++23 | 1.4kb | 2024-01-13 06:04:21 | 2024-01-13 06:04:22 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using pi = pair<int, int>;
constexpr int N = 100'000;
struct MexSet {
set<int> nums;
vector<int> cnt;
MexSet(int n) {
for (int i = 0; i <= n; ++i) nums.insert(i);
cnt.resize(n);
}
void Insert(int x) {
if (!cnt[x]) nums.erase(x);
++cnt[x];
}
void Erase(int x) {
--cnt[x];
if (!cnt[x]) nums.insert(x);
}
int Mex() {
return *nums.begin();
}
};
void solve() {
ios::sync_with_stdio(0); cin.tie(0);
multiset<int> lft;
int n, m; cin >> n >> m;
vector<vi> seg_beg(n+1), seg_end(n+1);
for (int i = 0; i < m; ++i) {
int l, r; cin >> l >> r; --l;
seg_beg[l].push_back(l);
seg_end[r].push_back(l);
}
vi ans(n);
MexSet ms(n);
int j = 0;
for (int i = 0; i < n; ++i) {
for (int x : seg_beg[i]) lft.insert(x);
for (int x : seg_end[i]) lft.erase(lft.find(x));
int act_bound = lft.empty() ? i : *lft.begin();
while (j < act_bound) ms.Erase(ans[j++]);
ms.Insert(ans[i] = ms.Mex());
}
for (int x : ans) cout << x+1 << ' ';
cout << '\n';
}
int main() {
ios::sync_with_stdio(0); cin.tie(0);
int t; cin >> t;
while (t--) {
solve();
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 447ms
memory: 17612kb
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