QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#136151#5719. Perfect FlushNicolas125841WA 18ms4608kbC++171.6kb2023-08-07 13:09:082023-08-07 13:09:11

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-07 13:09:11]
  • 评测
  • 测评结果:WA
  • 用时:18ms
  • 内存:4608kb
  • [2023-08-07 13:09:08]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

int main(){
    cin.tie(NULL)->sync_with_stdio(false);

    int n, k, v;
    cin >> n >> k;

    vector<int> ar(n);
    for(int i = 0; i < n; i++)
        cin >> ar[i];

    vector<bool> found(k + 1, false);
    vector<bool> last(n, false);

    for(int i = n - 1; i >= 0; i--){
        if(!found[ar[i]]){
            found[ar[i]] = true;
            last[i] = true;
        }
    }    

    int lb = 1;
    vector<bool> mex(k + 2, false);
    vector<int> stack;
    vector<int> result;

    mex[0] = true;

    for(int i = 0; i < n; i++){
        if(lb == ar[i]){
            stack.clear();
            result.push_back(ar[i]);
            
            mex[ar[i]] = true;
        }else if(!mex[ar[i]]){
            if(last[i]){
                int m_size = result.size();

                stack.push_back(ar[i]);

                for(int j = 0; j < stack.size(); j++){
                    if(stack[j] > ar[i] || mex[stack[j]])
                        continue;

                    while(result.size() > m_size && result.back() > stack[j]){
                        mex[result.back()] = false;

                        result.pop_back();
                    }

                    mex[stack[j]] = true;

                    result.push_back(stack[j]);
                }

                stack.clear();
            }else{
                stack.push_back(ar[i]);
            }
        }

        while(mex[lb])
            lb++;
    }

    for(int &r : result)
        cout << r << " ";
    cout << "\n";
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 3452kb

input:

6 3
3
2
1
3
1
3

output:

2 1 3 

result:

ok single line: '2 1 3 '

Test #2:

score: 0
Accepted
time: 1ms
memory: 3528kb

input:

10 5
5
4
3
2
1
4
1
1
5
5

output:

3 2 1 4 5 

result:

ok single line: '3 2 1 4 5 '

Test #3:

score: 0
Accepted
time: 16ms
memory: 4608kb

input:

200000 100000
29798
79235
44935
20368
15319
34973
11273
40142
82579
68354
79772
77697
59566
18516
50787
76175
25710
47305
87751
59942
49064
26470
38196
44038
38745
39903
71503
18468
59632
23169
10201
26065
62767
44170
37027
69281
7161
62056
7829
13359
80329
68362
59458
6406
80936
96142
56500
57523
1...

output:

29798 11273 40142 68354 79772 18516 25710 47305 59942 26470 38196 38745 39903 71503 10201 26065 62767 44170 7161 62056 7829 13359 68362 6406 56500 57523 6629 21853 21246 52201 56121 2741 29933 72408 96953 849 22024 68285 86159 24582 9177 8756 52266 85993 1699 18069 29470 31014 36759 93564 3053 13483...

result:

ok single line: '29798 11273 40142 68354 79772 ... 42906 92073 84291 44638 91402 '

Test #4:

score: -100
Wrong Answer
time: 18ms
memory: 4516kb

input:

200000 70000
24584
6697
18673
38293
8404
24994
47707
37053
30991
13653
67519
33504
8731
20485
65913
55807
16427
57137
17079
19944
13392
34408
11797
35484
40943
15167
4562
40466
66626
37190
48145
56716
49502
4084
57593
14543
59858
57061
13403
18538
21409
12339
52049
43056
59512
15385
3130
51397
60057...

output:

6697 8404 13653 67519 8731 11797 35484 40943 15167 4084 12339 52049 3130 6322 8767 16015 20527 30616 51550 4523 6094 15289 17316 5595 17825 6206 2156 24377 29414 1700 3930 40882 5301 15760 17893 20597 33362 36891 36937 59629 4205 8729 48006 60002 6479 7071 11817 20748 16682 20275 31641 31645 42991 4...

result:

wrong answer 1st lines differ - expected: '6697 8404 13653 67519 8731 117...8 33022 60886 53554 21126 54187', found: '6697 8404 13653 67519 8731 117... 33022 60886 53554 21126 54187 '