QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#136854#238. Distinct ValuesOrange_JuiCE#100 ✓113ms4928kbC++171.6kb2023-08-09 12:56:232023-08-09 12:56:26

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 12:56:26]
  • 评测
  • 测评结果:100
  • 用时:113ms
  • 内存:4928kb
  • [2023-08-09 12:56:23]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

#define ll long long
// #define int ll

int read(){
    int red=0, f_f=1; char c=getchar();
    while (c<'0'||c>'9'){if (c=='-')f_f=-1;c=getchar();}
    while (c>='0'&&c<='9'){red=(red<<1)+(red<<3)+(c^48);c=getchar();}
    return f_f*red;
}

const int N = 1e5+5;

int n, m, l, r, t, b[N];
struct node {
    int l, r;
    bool operator <(const node &B) const {
        return (l < B.l) || (l == B.l && r > B.r);
    }
}a[N];
set<int>s;


void solve() {
    n = read(), m = read();
    for(int i = 1; i <= m; i++) {
        a[i].l = read(), a[i].r = read();
    }
    for(int i = 1; i <= n; i++) b[i] = 1;
    sort(a+1, a+1+m);
    l = 0, r = 0, t = 1;
    s.clear();
    for(int i = 1; i <= m; i++) {
        if(a[i].l >= l && a[i].r <= r) continue;
        if(r < a[i].l) {
            s.clear();
            for(int j = a[i].l+1; j <= a[i].r; j++)
                b[j] = b[j-1]+1;
            l = a[i].l, r = a[i].r;
            t = r-l+1;
        }
        else {
            for(int j = l; j < a[i].l; j++)
                s.insert(b[j]);

            for(int j = r+1; j <= a[i].r; j++) {
                if(s.size()) {
                    b[j] = *(s.begin());
                    s.erase(s.begin());
                }
                else {
                    b[j] = ++t;
                } 
            }
            l = a[i].l, r = a[i].r;
        }
    }
    for(int i = 1; i < n; i++) printf("%d ", b[i]);
    printf("%d\n", b[n]);
}

signed main() {
    int T = read();
    while (T--) {
        solve();
    }
    return 0;
}
/*
1
5 2
1 3
3 5
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 113ms
memory: 4928kb

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