QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#136719#238. Distinct ValuesPanC_ake#100 ✓200ms12472kbC++201.7kb2023-08-09 10:28:452023-08-09 10:28:49

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 10:28:49]
  • 评测
  • 测评结果:100
  • 用时:200ms
  • 内存:12472kb
  • [2023-08-09 10:28:45]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define int long long

const int N = 2e5 + 10;
const int inf = 0x3f3f3f3f3f3f3f3f;
const int mod = 998244353;

int n, m, p[N], ans[N];
int evt[N];

int find(int x) {
    return p[x] == x? p[x]: p[x] = find(p[x]);
}

void merge(int x, int y) {
    x = find(x), y = find(y);
    if(x == y) return;
    p[x] = y;
}

int mn[N * 4];

void change(int id, int l, int r, int x, int v) {
    if(l == r) {
        mn[id] += v;
        return;
    }
    int mid = (l + r) / 2;
    if(x <= mid) change(id * 2, l, mid, x, v);
    else change(id * 2 + 1, mid + 1, r, x, v);
    mn[id] = min(mn[id * 2], mn[id * 2 + 1]);
}

int Bsearch(int id, int l, int r) {
    if(l == r) return l;
    int mid = (l + r) / 2;
    if(mn[id * 2] == 0) return Bsearch(id * 2, l, mid);
    else return Bsearch(id * 2 + 1, mid + 1, r);
}

void solve() {
    cin >> n >> m;
    for(int i = 1; i <= n; i++) {
        ans[i] = 0;
        evt[i] = i;
        p[i] = i;
    }
    for(int i = 1; i <= 4 * n; i++) mn[i] = 0;
    for(int i = 1; i <= m; i++) {
        int x, y;
        cin >> x >> y;
        evt[x] = max(evt[x], y);
    }
    for(int i = 1; i <= n; i++) {
        int l = find(i);
        int r = find(evt[i]);
        for(int j = (ans[l]? l + 1: l); j <= r; j++) {
            int v = Bsearch(1, 1, n);
            ans[j] = v;
            merge(j - 1, j);
            change(1, 1, n, v, 1);
        }
        change(1, 1, n, ans[i], -1);
    }
    for(int i = 1; i <= n; i++) cout << ans[i] << " ";
    cout << endl;
}

signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    int t = 1;
    cin >> t;
    while(t--) solve();
}

详细

Test #1:

score: 100
Accepted
time: 200ms
memory: 12472kb

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