QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#56716#238. Distinct Valuesmango8023TL 0ms0kbC++1.9kb2022-10-21 09:18:242022-10-21 09:18:26

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-10-21 09:18:26]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:0kb
  • [2022-10-21 09:18:24]
  • 提交

answer

#include <cstdio>
#include <iostream>
#include <queue>
#include <unordered_set>
using namespace std;

const int N = 1E5+5;
int n, k;

queue<int> a[N]; //left bound positive, right bound negative
unordered_set<int> effect[N]; //numbers limited by each pairs
unordered_set<int> b[N]; //limited numbers
unordered_set<int> activated; //activated pairs
int main(){
    int t;
    cin>>t;
    for(int o = 0; o<t; o++){
        cin>>k>>n;
        for(int i=0;i<=k || i<=n;i++){
            while(!a[i].empty()) a[i].pop();
            effect[i].clear();
            b[i].clear();
        }
        activated.clear();
        for(int i = 1; i<=n; i++){
            int x,y;
            cin>>x>>y;
            a[x].push(i); // a[1]={1}, a[2]={2}
            a[y].push(-i);// a[3]={-1},a[4]={-2}
        }
        int num = 1;
        for(int i = 1; i<=k; i++){
            queue<int> closing;
            while(!a[i].empty()){
                int x = a[i].front();
                a[i].pop();
                if(x>0){
                    activated.insert(x); // activated={}
                }
                else{
                    closing.push(-x); // closing={}
                }
            }
            // 1 2 3...,1000,1,1001,2,1002,3,1003,4,1004
            while(!b[num].empty()) num++; // n/4*n/2=n^2/8
            cout<<num; // num=1, 2, 3, 1
            if(i < k) cout<<' ';
            for(int j : activated){
                effect[j].insert(num); // effect[1]={1,2,3} effect[2]={2,3,1}
                b[num].insert(j); // b[1]={} b[2]={} b[3]={}
            }
            while(!closing.empty()){
                int x = closing.front(); // x=2
                closing.pop();
                activated.erase(x);
                for(int j : effect[x]){ //
                    b[j].erase(x); // 
                    num = min(num, j); // num=1
                }
            }
        }
        cout<<endl;
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Time Limit Exceeded

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: