QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#136760#238. Distinct Valuesckz#100 ✓1347ms9284kbC++201.7kb2023-08-09 10:59:412023-08-09 10:59:44

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:59:44]
  • 评测
  • 测评结果:100
  • 用时:1347ms
  • 内存:9284kb
  • [2023-08-09 10:59:41]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
#define all(a) (a).begin(), (a).end()
using namespace std;

const int N = 1e5 + 10;

int n, m;

int seg[N], mi[N], a[N];

multiset<int> st;

void solve(){
    st.clear();
    cin >> n >> m;
    for(int i = 1 ; i <= n + 5; i ++) {
        mi[i] = 1e9;
        seg[i] = 1e9;
    }
    for(int i = 1 ; i <= m ; i ++) {
        int l, r;
        cin >> l >> r;
        seg[r] = min(seg[r], l);
    }
    for(int i = n ; i >= 1; i --) mi[i] = min(seg[i], mi[i + 1]);
    int now = 0;
    st.insert(0);
    int ls = 0;
    for(int i = 1; i <= n ; i ++){
        int L = mi[i];
        int R = i - 1;
        // cout << L << " " << R << "\n";
        if(L > R) {
            a[i] = 1;
        }else{
            // cout << i << " " << now << " " << L << "\n";
            while(now < L){
                st.erase(st.find(a[now]));
                now ++;
            }
            // cout << i << " " << st.size() << "\n";
            if(L == ls){
                for(int res = a[i - 1]; ; res ++){
                    if(!st.count(res)){
                        a[i] = res;
                        break;
                    }
                }                
            }else{
                for(int res = 1; ; res ++){
                    if(!st.count(res)){
                        a[i] = res;
                        break;
                    }
                }
            }
        }
        ls = L;
        st.insert(a[i]);
    }
    for(int i = 1; i <= n ; i ++) cout << a[i] << " ";
    cout << "\n";


}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);cout.tie(nullptr);
    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: 1347ms
memory: 9284kb

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