Skip to content

Commit

Permalink
20240603 openmi's submission for CF802B (Yawn-Sean#3167)
Browse files Browse the repository at this point in the history
  • Loading branch information
TrespassingoO authored Jun 3, 2024
1 parent d181e9d commit 297e93b
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions daily_problems/2024/06/0603/personal_submission/cf802b_openmi.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
void solve() {
int n, k;
cin >> n >> k;
int x;
vi borrow(n), nxt(n), last(n, n), has(n);
rep (i, 0, n) {
cin >> x;
borrow[i] = x - 1;
}
br (i, n-1, 0) {
nxt[i] = last[borrow[i]];
last[borrow[i]] = i;
}
priority_queue<ll> pq;
int ans = 0, cnt = 0;
rep (i, 0, n) {
while (pq.size() and !has[pq.top() % n]) {
pq.pop();
}
if (!has[borrow[i]]) {
if (cnt == k) {
has[pq.top() % n] = 0;
cnt--;
}
has[borrow[i]] = 1;
cnt ++;
ans ++;
}
pq.push(1LL * nxt[i] * n + borrow[i]);
}
cout << ans << nl;

}

0 comments on commit 297e93b

Please sign in to comment.