QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#136648 | #238. Distinct Values | BoulevardDust# | 100 ✓ | 528ms | 15160kb | C++17 | 1.2kb | 2023-08-09 09:42:24 | 2023-08-09 09:42:28 |
Judging History
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;
}
Details
Tip: Click on the bar to expand more detailed information
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