QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#136658#238. Distinct Valueswtn135687#100 ✓268ms10504kbC++201.1kb2023-08-09 09:47:332023-08-09 09:47:36

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 09:47:36]
  • 评测
  • 测评结果:100
  • 用时:268ms
  • 内存:10504kb
  • [2023-08-09 09:47:33]
  • 提交

answer

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

const int N = 1e5+10,mo = 1e9+7;
ll n, m, a[N];
struct node{
    ll l, r;
    bool operator < (const node& x){
        if (l != x.l)return l < x.l;
        return r > x.r;
    }
}b[N];
set<ll> st;



inline void solve(){
    cin >> n >> m;
    st.clear();
    for (int i = 1; i <= n; i++)a[i] = 1, st.insert(i);
    for (int i = 1, l, r; i <= m; i++){
        cin >> l >> r;
        b[i] = {l, r};
    }
    ll l = 1, r = 0;
    sort(b + 1, b + 1 + m);
    for (int i = 1; i <= m; i++){
        if (b[i].r <= r)continue;
        while (l < b[i].l)st.insert(a[l]), l++;
        r = max(r, l - 1);
        while (r + 1 <= b[i].r){
            r++;
            a[r] = *st.begin();
            // cerr << r << " " << a[r] << endl;
            st.erase(*st.begin());
        }
    }
    for (int i = 1; i <= n; i++)cout << a[i] << " ";
    cout << endl;
}



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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 268ms
memory: 10504kb

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