QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#136770 | #238. Distinct Values | 4k2kok# | 100 ✓ | 275ms | 10988kb | C++20 | 1.6kb | 2023-08-09 11:08:25 | 2023-08-09 11:08:28 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define INF 0x3f3f3f3f
#define PI acos(-1)
#define io ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define mem(a,b) memset((a),(b),sizeof(a))
typedef long long ll;
typedef unsigned long long ull;
#define int long long
#define db long double
const double eps = 1e-6;
const int mod = 1e9 + 7;
const int maxn = 1e5 + 10;
int n, m;
struct node {
int l, r;
bool operator < (const node &n1) const {
if (l == n1.l) return r < n1.r;
return l < n1.l;
}
};
vector<node> vv;
int ans[maxn];
void solve() {
vv.clear();
cin >> n >> m;
for (int i = 1, l, r; i <= m; i++) {
cin >> l >> r;
vv.push_back({l, r});
}
sort(vv.begin(), vv.end());
for (int i = 1; i <= n; i++) ans[i] = 1;
set<int> s;
for (int i = 1; i <= n; i++) {
s.insert(i);
}
int lastl = 1, lastr = 0;
for (int i = 0; i < vv.size(); i++) {
if (vv[i].l > lastl) {
for (int j = lastl; j < vv[i].l; j++) {
s.insert(ans[j]);
}
lastl = vv[i].l;
}
int nowl = max(lastr + 1, vv[i].l);
for (int j = nowl; j <= vv[i].r; j++) {
ans[j] = *s.begin();
s.erase(ans[j]);
}
lastr = max(lastr, vv[i].r);
}
for (int i = 1; i <= n; i++) {
cout << ans[i] << ' ';
}
cout << '\n';
}
signed main(){
io;
int T = 1;
cin >> T;
while(T--) {
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 275ms
memory: 10988kb
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