QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#136644#238. Distinct Valuesnameless_story#100 ✓132ms4468kbC++20770b2023-08-09 09:39:232023-08-09 09:39:25

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:39:25]
  • 评测
  • 测评结果:100
  • 用时:132ms
  • 内存:4468kb
  • [2023-08-09 09:39:23]
  • 提交

answer

#include<bits/stdc++.h>

using namespace std;

void solve(){
    priority_queue<int,vector<int>,greater<int>> q;
    int n,m; cin>>n>>m;
    for (int i=1;i<=n;++i) q.push(i);
    vector r(n+1,n+1);
    vector a(n+1,0);
    for (int i=1;i<=m;++i){
        int x,y; cin>>x>>y;
        r[y]=min(r[y],x);
    }
    r[n]=min(r[n],n);
    for (int i=n-1;i>=1;--i){
        r[i]=min(r[i],i);
        r[i]=min(r[i+1],r[i]);
    }
    int j=1;
    for (int i=1;i<=n;++i){
        int l=r[i];
        while (j<l){
            q.push(a[j]);
            ++j;
        }
        a[i]=q.top();
        q.pop();
        cout<<a[i]<<" \n"[i==n];
    }
}
int main(){
    ios::sync_with_stdio(0); cin.tie(0);
    int T; cin>>T;
    while (T--) solve();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 132ms
memory: 4468kb

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