QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#355751 | #7942. $K$ Subsequences | ngpin04# | TL | 784ms | 9432kb | C++14 | 1.5kb | 2024-03-17 05:39:38 | 2024-03-17 05:39:40 |
Judging History
answer
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define ALL(x) x.begin(), x.end()
#define bit(x) (1LL << (x))
#define getbit(x, i) (((x) >> (i)) & 1)
using namespace std;
typedef pair<int,int> ii;
const int INF = 1e9;
int t;
int n, k;
int A[200003];
int ans[200003];
bool cek(int x)
{
multiset<ii> st;
for(int i = 1; i <= k; i++) st.insert({0, i});
for(int i = 1; i <= n; i++)
{
if(A[i] == 1)
{
auto it = st.upper_bound({x-1, INF});
if(it == st.begin()) return 0;
--it;
ans[i] = it->se;
ii tmp = {it->fi+1, it->se};
st.erase(it);
st.insert(tmp);
}
else
{
auto it = --st.end();
ans[i] = it->se;
if(it->fi != 0)
{
ii tmp = {it->fi-1, it->se};
st.erase(it);
st.insert(tmp);
}
}
}
return 1;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> t;
while(t--)
{
cin >> n >> k;
for(int i = 1; i <= n; i++) cin >> A[i];
int kir = 0, kan = n;
while(kir < kan)
{
int mid = (kir+kan)/2;
if(cek(mid)) kan = mid;
else kir = mid+1;
}
cek(kir);
// cout << kir << "\n";
for(int i = 1; i <= n; i++)
{
cout << ans[i] << " ";
} cout << "\n";
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3536kb
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:
2 2 2 2 2 1 2 3 3 3 2 2 2 1 3 3 2 2 3 2 3 2 1 1 4 3 2 1 4 3 2 1 4 3 2 1
result:
ok Correct (5 test cases)
Test #2:
score: 0
Accepted
time: 49ms
memory: 3504kb
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 2 2 2 2 2 2 2 1 1 2 2 2 2 2 2 2 2 2 1 7 6 7 7 7 7 5 7 6 7 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 3 3 3 2 2 3 2 3 1 1 1 1 1 1 1 1 1 10 10 9 8 7 6 5 4 3 2 4 4 4 4 4 4 3 4 4 2 3 2 3 2 3 3 3 3 3 4 3 4 4 2 1 4 4 7 7 6 5 4 3 2 1 7 7 6 6 6 6 6 6 6 5 6 1 1 1 1 1 1 1 1 1 3...
result:
ok Correct (18434 test cases)
Test #3:
score: 0
Accepted
time: 124ms
memory: 5112kb
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:
3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 ...
result:
ok Correct (1 test case)
Test #4:
score: 0
Accepted
time: 218ms
memory: 5344kb
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 152 152 152 152 152 152 152 152 152 152 152 152 152 152 152 152 152 152 152 152 152 152 152 152 152 152 152 152 152 152 152 152 152 152 152 152 152 152 152 152 152 152 152 152 152 152 152 152 152 152 152 152 152 152 152 152 152 152 152 152 152 152 152 152 152 152 152 152 152 152 152 152 ...
result:
ok Correct (1 test case)
Test #5:
score: 0
Accepted
time: 201ms
memory: 5188kb
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 136 136 135 135 136 136 136 136 135 135 135 136 135 136 135 136 136 134 134 136 136 136 135 136 136 136 135 136 135 136 136 136 135 135 135 134 136 136 133 133 136 135 134 136 135 135 135 134 133 136 135 134 133 136 136 136 136 136 135 135 136 136 135 134 134 134 136 135 136 136 136 136 134 ...
result:
ok Correct (1 test case)
Test #6:
score: 0
Accepted
time: 784ms
memory: 9432kb
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:
86240 86239 86240 86240 86238 86237 86236 86235 86234 86240 86240 86233 86240 86240 86240 86239 86238 86240 86239 86238 86232 86231 86230 86229 86240 86240 86228 86227 86226 86225 86240 86240 86240 86239 86238 86237 86236 86235 86234 86233 86240 86240 86232 86240 86240 86231 86230 86229 86240 86239 ...
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...