QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#691218#7942. $K$ Subsequencesucup-team3699#RE 55ms3844kbC++141.7kb2024-10-31 10:27:102024-10-31 10:27:11

Judging History

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

  • [2024-10-31 10:27:11]
  • 评测
  • 测评结果:RE
  • 用时:55ms
  • 内存:3844kb
  • [2024-10-31 10:27:10]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N = 1e5 + 5;
int a[N];
int n, k;
bool check(int x){
    set<pair<int, int> > s;
    for(int i = 1; i <= k; i++){
        s.insert({0, i});
    }
    for(int i = 1; i <= n; i++){
        if(a[i] == -1){
            pair<int, int> back = *prev(s.end());
            s.erase(prev(s.end()));
            back.first -= 1;
            s.insert(back);
        }else{
            if(s.begin()->first >= x)
                return 0;
            pair<int, int> back = *(s.begin());
            s.erase(s.begin());
            back.first += 1;
            s.insert(back);
        }
    }
    return 1;
}
void solve(){
    cin >> n >> k;
    for(int i = 1; i <= n; i++){
        cin >> a[i];
    }

    int ll = 0, rr = n;

    while(ll < rr){
        int mid = ll + rr >> 1;
        if(check(mid)){
            rr = mid;
        }else{
            ll = mid + 1;
        }
    }

    set<pair<int, int> > s;
    for(int i = 1; i <= k; i++){
        s.insert({0, i});
    }
    for(int i = 1; i <= n; i++){
        if(a[i] == -1){
            pair<int, int> back = *prev(s.end());
            s.erase(prev(s.end()));
            cout << back.second << ' ';
            back.first -= 1;
            s.insert(back);
        }else{
            pair<int, int> back = *(s.begin());
            s.erase(s.begin());
            cout << back.second << ' ';
            back.first += 1;
            s.insert(back);
        }
    }
    cout << '\n';
}
signed 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: 0ms
memory: 3548kb

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 1 
2 2 1 1 
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: 0
Accepted
time: 55ms
memory: 3844kb

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 
2 1 2 2 1 1 1 2 1 2 
1 1 2 1 2 2 1 1 1 2 
1 2 2 2 2 2 3 3 2 2 
1 1 1 1 1 1 1 1 1 
1 1 1 1 1 1 1 1 
3 2 1 1 2 3 1 1 3 2 
1 1 1 1 1 1 1 1 1 
10 10 1 2 3 4 5 6 7 8 
4 4 4 4 4 4 1 1 1 2 
1 2 2 1 1 1 1 1 3 
1 2 2 2 3 4 4 4 
7 7 1 2 3 4 5 6 6 6 
1 1 6 6 6 5 5 6 6 
1 1 1 1 1 1 1 1 1 
1...

result:

ok Correct (18434 test cases)

Test #3:

score: -100
Runtime Error

input:

1
199996 3
1 -1 1 1 1 1 -1 -1 -1 1 1 -1 1 -1 1 1 -1 -1 1 1 1 1 -1 1 -1 -1 -1 1 -1 1 1 1 1 1 1 1 -1 -1 -1 1 -1 -1 1 1 -1 -1 -1 1 -1 1 1 -1 1 -1 -1 1 1 1 1 -1 1 1 1 1 1 1 1 1 -1 -1 -1 -1 1 1 -1 1 1 -1 1 -1 -1 -1 -1 -1 1 1 -1 -1 1 1 -1 1 -1 1 1 -1 1 1 1 -1 1 -1 1 1 1 -1 -1 -1 1 1 -1 -1 1 -1 -1 -1 -1 -1...

output:


result: