QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#707779#7942. $K$ Subsequencesbilbo_b#WA 21ms3632kbC++171.2kb2024-11-03 17:30:222024-11-03 17:30:23

Judging History

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

  • [2024-11-03 17:30:23]
  • 评测
  • 测评结果:WA
  • 用时:21ms
  • 内存:3632kb
  • [2024-11-03 17:30:22]
  • 提交

answer

#include <bits/stdc++.h>

#define int long long
#define x first
#define y second

using namespace std;

signed main() {
    cin.tie(0);
    cout.tie(0);
    ios_base::sync_with_stdio(0);

    int t;
    cin >> t;
    while(t--) {
        int n, k, x;
        cin >> n >> k;
        vector<int> a(n);
        vector<int> ans(n);
        
        set<pair<int, int> > s;
        for (int i = 0; i < n; ++i) {
            cin >> x;
            if (x == 1) {
                if (s.size() < k) {
                    s.insert({1, s.size()});
                    ans[i] = s.size();
                } else {
                    auto t = *s.begin();
                    s.erase(t);
                    ans[i] = t.y + 1;
                    s.insert({t.x + 1, t.y});
                }
            } else {
                if (s.empty()) {
                    ans[i] = 1;
                } else {
                    auto t = *s.rbegin();
                    s.erase(t);
                    ans[i] = t.y + 1;
                    s.insert({t.x - 1, t.y});
                }
            }
        }
        for (auto i : ans) {
            cout << i << " ";
        }
        cout << '\n';
    }
 
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3632kb

input:

5
3 2
1 -1 1
4 2
-1 1 1 -1
7 3
1 1 1 1 1 1 1
10 3
1 1 1 1 -1 -1 1 1 1 1
12 4
1 1 1 1 -1 -1 -1 -1 1 1 1 1

output:

1 1 2 
1 1 2 2 
1 2 3 1 2 3 1 
1 2 3 1 1 3 3 1 2 3 
1 2 3 4 4 3 2 1 1 2 3 4 

result:

ok Correct (5 test cases)

Test #2:

score: -100
Wrong Answer
time: 21ms
memory: 3536kb

input:

18434
10 1
-1 1 1 -1 -1 1 -1 -1 1 1
10 2
-1 -1 -1 1 1 -1 1 1 1 1
10 2
1 -1 -1 -1 -1 1 1 -1 1 1
10 7
1 1 -1 1 -1 1 1 -1 -1 1
9 1
-1 1 -1 1 1 -1 1 -1 1
8 1
-1 -1 -1 -1 1 1 -1 -1
10 3
-1 -1 -1 1 1 1 1 -1 -1 -1
9 1
1 -1 -1 1 -1 -1 -1 -1 -1
10 10
-1 1 1 1 1 1 1 1 1 1
10 4
-1 1 -1 1 -1 1 1 -1 1 1
9 3
1 1 ...

output:

1 1 1 1 1 1 1 1 1 1 
1 1 1 1 2 2 2 1 2 1 
1 1 1 1 1 2 1 2 1 1 
1 2 2 3 3 4 5 5 4 6 
1 1 1 1 1 1 1 1 1 
1 1 1 1 1 1 1 1 
1 1 1 1 2 3 1 1 3 2 
1 1 1 1 1 1 1 1 1 
1 1 2 3 4 5 6 7 8 9 
1 1 1 2 2 3 4 4 1 2 
1 2 2 1 3 3 1 1 3 
1 2 2 3 4 2 4 4 
1 1 2 3 4 5 6 7 7 7 
1 1 1 2 2 2 3 4 4 
1 1 1 1 1 1 1 1 1 
1 2...

result:

wrong answer Jury found better answer than participant (test case 3)