QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#691237 | #7942. $K$ Subsequences | ucup-team3699# | TL | 818ms | 10500kb | C++14 | 1.8kb | 2024-10-31 10:31:09 | 2024-10-31 10:31:16 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx,popcnt,sse4,abm")
#pragma GCC optimize("Ofast","inline","-ffast-math")
#pragma GCC target("avx,sse2,sse3,sse4,mmx")
using namespace std;
const int N = 2e5 + 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: 3496kb
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: 66ms
memory: 3500kb
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: 0
Accepted
time: 163ms
memory: 5116kb
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:
1 1 1 2 3 1 1 3 2 2 3 3 3 3 3 1 1 3 3 1 2 3 3 3 3 2 1 1 1 1 2 3 1 2 3 1 1 3 2 2 2 1 1 2 2 1 3 3 3 3 1 1 1 1 3 3 1 2 3 3 3 1 2 3 1 2 3 1 1 3 2 1 1 2 2 2 3 3 3 3 2 1 3 2 2 3 3 2 2 3 3 3 3 3 1 1 1 2 3 3 3 3 3 1 2 2 1 3 3 1 1 3 3 3 2 1 3 2 1 1 2 3 3 3 1 2 3 1 2 2 2 2 2 3 1 1 3 2 1 1 1 1 1 1 2 2 1 1 1 1 ...
result:
ok Correct (1 test case)
Test #4:
score: 0
Accepted
time: 267ms
memory: 5408kb
input:
1 199998 152 -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:
152 152 152 151 151 151 150 149 148 147 146 146 146 145 145 145 144 143 143 143 142 142 142 142 143 143 142 142 143 144 144 143 142 142 142 142 142 142 143 143 142 141 140 139 138 137 136 136 136 136 137 137 136 136 137 137 137 137 137 137 137 137 137 137 137 137 137 137 136 136 136 136 137 138 139 ...
result:
ok Correct (1 test case)
Test #5:
score: 0
Accepted
time: 271ms
memory: 5120kb
input:
1 199996 136 -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 1...
output:
136 136 1 2 3 4 4 4 4 3 3 3 3 4 4 3 3 4 5 6 7 7 7 7 6 6 6 6 7 7 6 6 6 5 5 5 5 6 7 8 9 10 10 9 8 7 7 7 6 5 4 3 2 1 136 136 1 2 2 2 3 4 4 4 5 6 7 8 8 7 7 7 7 7 6 6 7 8 9 9 9 9 8 7 6 6 7 7 6 5 4 4 4 4 5 6 7 8 8 7 7 8 9 10 11 12 13 14 15 16 17 17 16 15 15 16 17 18 19 19 19 20 20 20 21 22 22 22 23 23 22 ...
result:
ok Correct (1 test case)
Test #6:
score: 0
Accepted
time: 818ms
memory: 10500kb
input:
1 199998 86240 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:
1 2 2 2 3 4 5 6 7 7 7 8 8 8 8 7 6 6 7 8 9 10 11 12 12 12 13 14 15 16 16 16 16 15 14 13 12 11 10 9 9 9 8 8 8 7 6 5 5 6 6 5 4 4 5 5 4 4 5 5 5 5 5 5 5 5 5 6 7 8 9 9 9 9 9 9 9 9 8 8 9 10 10 9 8 7 6 5 5 6 7 8 8 7 6 6 7 7 6 6 6 6 7 8 8 7 6 6 6 5 4 3 3 4 4 3 3 3 3 3 2 2 2 1 86240 86239 86238 86237 86237 86...
result:
ok Correct (1 test case)
Test #7:
score: -100
Time Limit Exceeded
input:
1 199998 196586 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...