QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#136673#238. Distinct ValuesDelay_for_five_minutes#100 ✓277ms9176kbC++201.1kb2023-08-09 09:55:562023-08-09 09:55:57

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:55:57]
  • 评测
  • 测评结果:100
  • 用时:277ms
  • 内存:9176kb
  • [2023-08-09 09:55:56]
  • 提交

answer

#include<bits/stdc++.h>
#define maxn 100005
int nxt[maxn],ans[maxn];
int n,m;
void solve() {
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++) {
        nxt[i] = 0;
    }
    for(int i=1;i<=m;i++) {
        int l,r;
        scanf("%d%d",&l,&r);
        nxt[l] = std::max(nxt[l], r);
    }
    for(int i=1;i<=n;i++) {
        nxt[i] = std::max(nxt[i-1],nxt[i]);
        if (nxt[i] < i) nxt[i] = i;
    }
    std::set<int> st;
    for(int i=1;i<=n;i++) {
        st.insert(i);
    }
    for(int i=1;i<=n;i++) {
        int now = *st.begin();
        st.erase(now);
        ans[now] = i;
        for(;;) {
            now = nxt[now] + 1;
            std::set<int> ::iterator it = st.lower_bound(now) ;
            if (it == st.end()) break;
            else {
                now = *it;
                st.erase(it);
            }
            ans[now] = i;
        }
    }
    for(int i=1;i<=n;i++) {
        printf("%d ",ans[i]);
    }putchar('\n');
}
int main() {
    int T;
    scanf("%d",&T);
    while(T--) {
        solve();
    }
}

详细

Test #1:

score: 100
Accepted
time: 277ms
memory: 9176kb

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