社区讨论
72分求调qwq
P3419[POI 2005] SAM-Toy Cars参与者 1已保存回复 0
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 0 条
- 当前快照
- 1 份
- 快照标识符
- @mdisvxr3
- 此快照首次捕获于
- 2025/07/25 20:31 7 个月前
- 此快照最后确认于
- 2025/07/25 20:31 7 个月前
CPP
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5+10;
ll n,k,p;
ll a[N];
ll last[N];
ll next[N];
ll ans;
bool vis[N];
struct node{
ll nxt,id;
bool operator < (const node&x) const{
return nxt < x.nxt;
}
};
priority_queue <node> q;
int main(){
cin >> n >> k >> p;
for(int i=1;i<=p;i++) cin>>a[i];
for(int i=p;i>=1;i--){
if(!last[a[i]]) next[i] = 1e18+5;
else next[i] = last[a[i]];
last[a[i]]=i;
}
for(int i=1;i<=p;i++){
if(vis[a[i]]){
k++;
node nw;
nw.nxt = next[i];
nw.id = a[i];
q.push(nw);
}
else{
if(q.size()>=k) vis[q.top().id]=0,q.pop();
node nw;
nw.nxt = next[i];
nw.id = a[i];
q.push(nw);
vis[a[i]]=1;
ans++;
}
}
cout << ans;
}
回复
共 0 条回复,欢迎继续交流。
正在加载回复...