QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#162582#238. Distinct ValuesSolitaryDream#100 ✓471ms19372kbC++141.0kb2023-09-03 14:43:152023-09-03 14:43:15

Judging History

你现在查看的是最新测评结果

  • [2023-09-03 14:43:15]
  • 评测
  • 测评结果:100
  • 用时:471ms
  • 内存:19372kb
  • [2023-09-03 14:43:15]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define FOR(i,s,t) for(int i=(s),_t=(t); i<=_t; ++i)
#define DOR(i,s,t) for(int i=(s),_t=(t); i>=_t; --i)
typedef long long ll;
const int N=1e5+50;
vector<int> a[N],b[N];
int ans[N];
void solve() {
    int n,m;
    cin >> n >> m;
    FOR(i,1,n) a[i].clear(),b[i].clear();
    FOR(i,1,m) {
        int l,r;
        cin >> l >> r;
        a[l].push_back(l);
        b[r].push_back(l);
    }
    multiset<int> S,W;
    FOR(i,1,n) W.insert(i);
    int q=1;
    FOR(i,1,n) {
        for(auto x: a[i]) S.insert(x);
        int p=i;
        if(S.size()) p=*S.begin();
        while(q<p) {
            W.insert(ans[q]);
            q++;
        }
        ans[i]=*W.begin();
        W.erase(W.begin());
        for(auto x: b[i]) S.erase(S.find(x));
        cout << ans[i] << " \n"[i==n];
    }
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int T;
    cin >> T;
    while(T--) {
        solve();
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 471ms
memory: 19372kb

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