QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#242187 | #5719. Perfect Flush | Fyind | WA | 472ms | 34456kb | C++20 | 3.6kb | 2023-11-07 00:33:13 | 2023-11-07 00:33:14 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define _ << " " <<
#define ls (o << 1)
#define rs (o << 1 | 1)
const int maxn = 2e5 + 5;
typedef pair<int,int> pii;
#include<bits/extc++.h>
using namespace __gnu_pbds;
tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> rest;
#define sz(x) ((int)x.size())
int A[maxn];
int n, k;
int last[maxn];
int pre[maxn];
int m[maxn<<2];
void pushup(int o) {
m[o] = min(m[ls], m[rs]);
}
void modi(int o, int l, int r, int pos, int v) {
if (l == r)
m[o] = v;
else {
int mid = l + r >> 1;
if (pos <= mid)
modi(ls, l, mid, pos, v);
else
modi(rs, mid + 1, r, pos, v);
pushup(o);
}
}
int ask(int o, int l, int r, int L, int R) {
if (l >= L && r <= R)
return m[o];
else {
int mid = l + r >> 1;
int ret = n + 1;
if (L <= mid)
ret = min(ret, ask(ls, l, mid, L, R));
if (R > mid)
ret = min(ret, ask(rs, mid + 1, r, L, R));
return ret;
}
}
int m2[maxn<<2];
void pushup2(int o) {
m2[o] = min(m2[ls], m2[rs]);
}
void modi2(int o, int l, int r, int pos, int v) {
if (l == r)
m2[o] = v;
else {
int mid = l + r >> 1;
if (pos <= mid)
modi2(ls, l, mid, pos, v);
else
modi2(rs, mid + 1, r, pos, v);
pushup2(o);
}
}
int ask2(int o, int l, int r, int L, int R) {
if (l >= L && r <= R)
return m2[o];
else {
int mid = l + r >> 1;
int ret = n + 1;
if (L <= mid)
ret = min(ret, ask2(ls, l, mid, L, R));
if (R > mid)
ret = min(ret, ask2(rs, mid + 1, r, L, R));
return ret;
}
}
int l;
set<int> pos[maxn];
bool check(int x) {
// cout << "CH" _ x << endl;
if (x == k) return true;
int p = ask2(1,1,k,1,x);
// cout << x _ p << endl;
int tal = ask(1,1,k,x+1,k);
// cout << tal _ x+1 << endl;
return tal >= p;
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> n >> k;
for (int i = 1;i <= n; ++i) cin >> A[i];
for (int i = n;i >= 1; --i) {
if (!last[A[i]]) {
last[A[i]] = i;
modi(1,1,k,A[i],i);
// cout << "I" _ A[i] _ i << endl;
}
pos[A[i]].insert(i);
}
vector<pii> B;
for (int i = 1;i <= n; ++i) {
if (!pre[A[i]]) pre[A[i]] = i, B.push_back({pre[A[i]],A[i]});
}
sort(B.begin(),B.end(),greater<>());
for (int i = 1;i <= k; ++i) modi2(1,1,k,i,pre[i]);
for (int i = 1;i <= k; ++i) {
rest.insert(i);
}
// cout << ask(1,1,k,4,5) << endl;
// cout << check(2) << endl;
vector<int> ans;
int r = 1;
for (int i = 1;i <= k; ++i) {
int L = 1, R = sz(rest);
while (L < R) {
int M = (L+R)/2;
if (check(*rest.find_by_order(M-1))) R = M;
else L = M+1;
}
// cout << i _ L << endl;
auto cur = *rest.find_by_order(L-1);
ans.push_back(cur);
rest.erase(cur);
modi(1,1,k,cur,n+1);
modi2(1,1,k,cur,n+1);
l = *pos[cur].lower_bound(l);
auto del = [&](int x) {
if (rest.find(x) == rest.end()) return;
auto it = pos[x].lower_bound(l);
if (it == pos[x].end()) modi2(1,1,k,x,n+1);
else modi2(1,1,k,x,*it);
};
while (r <= l) {
del(r++);
}
}
for (auto x : ans) cout << x << " ";
cout << '\n';
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 15576kb
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: 3ms
memory: 17104kb
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: -100
Wrong Answer
time: 472ms
memory: 34456kb
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 15319 99599 99573 99551 99316 99040 98918 98868 98650 98523 98384 98293 98052 97963 97884 97797 97736 97707 97511 97076 96953 96942 96710 96679 96564 96427 96240 96222 96058 95767 95471 95425 95386 95347 95237 95224 94903 94882 94863 94848 94635 94541 94330 94177 94016 93986 93985 93881 ...
result:
wrong answer 1st lines differ - expected: '29798 11273 40142 68354 79772 ...6 42906 92073 84291 44638 91402', found: '29798 11273 15319 99599 99573 ... 45439 77126 42906 44638 91402 '