QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#136709#238. Distinct ValuesS_Explosion#100 ✓151ms6004kbC++201.9kb2023-08-09 10:21:282023-08-09 10:21:31

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:21:31]
  • 评测
  • 测评结果:100
  • 用时:151ms
  • 内存:6004kb
  • [2023-08-09 10:21:28]
  • 提交

answer

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cstring>
#include <string>
#include <unordered_map>
#include <cmath>
#include <assert.h>
#include <map>
#include <set>
#include <utility>

template <typename Tp>
inline void read(Tp &x) {
    x = 0;
    bool f = true; char ch = getchar();
    for ( ; ch < '0' || ch > '9'; ch = getchar()) f ^= ch == '-';
    for ( ; ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 + (ch ^ 48);
    x = f ? x : -x;
}

const int N = 1e5;

int a[N + 5], R[N + 5], mn[N * 4 + 5];

void build(int p, int l, int r) {
    mn[p] = 0;
    if (l == r) return;
    int mid = (l + r) >> 1;
    build(p << 1, l, mid), build(p << 1 | 1, mid + 1, r);
}
void update(int p, int l, int r, int x, int k) {
    if (l == r) {
        mn[p] += k;
        return;
    }
    int mid = (l + r) >> 1;
    if (x <= mid) update(p << 1, l, mid, x, k);
    else update(p << 1 | 1, mid + 1, r, x, k);
    mn[p] = std::min(mn[p << 1], mn[p << 1 | 1]);
}
int find(int p, int l, int r) {
    if (l == r) return l;
    int mid = (l + r) >> 1;
    if (mn[p << 1] == 0) return find(p << 1, l, mid);
    else return find(p << 1 | 1, mid + 1, r);
}

int main() {
    int T;
    read(T);
    while (T--) {
        int n, m;
        read(n), read(m);
        for (int i = 1; i <= n; ++i) R[i] = i;
        for (int i = 1; i <= m; ++i) {
            int l, r;
            read(l), read(r);
            R[l] = std::max(R[l], r);
        }
        build(1, 1, n);
        int now = 1;
        for (int i = 1; i <= n; ++i) {
            while (R[now] < i) {
                update(1, 1, n, a[now], -1);
                ++now;
            }
            a[i] = find(1, 1, n);
            update(1, 1, n, a[i], 1);
        }
        for (int i = 1; i <= n; ++i) printf("%d ", a[i]);
        puts("");
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 151ms
memory: 6004kb

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