1 条题解
-
1
#include<iostream> #include<stdio.h> #include<queue> #include<algorithm> using namespace std; const int maxn=1e6+5; struct node { int xu,t; bool operator<(const node &a)const { if(t==a.t)return xu>a.xu; return t>a.t; } }; priority_queue<node>q; int a[maxn],b[maxn]; int num[maxn]; int main() { int n,m; scanf("%d %d",&n,&m); for(int i=1; i<=m; i++)scanf("%d",&a[i]),b[i]=a[i]; sort(b+1,b+m+1); int k=unique(b+1,b+m+1)-b-1; int tot=0,ans=0; for(int i=1; i<=m; i++) { a[i]=lower_bound(b+1,b+k+1,a[i])-b; if(num[a[i]])num[a[i]]++,ans++; else if(tot<n)tot++,num[a[i]]=1; else { node res=q.top(); q.pop(); while(num[a[res.xu]]!=res.t)res=q.top(),q.pop(); num[a[i]]++,num[a[res.xu]]=0; } q.push((node)<%i,num[a[i]]%>); } printf("%d\n",ans); return 0; }
- 1
信息
- ID
- 1269
- 时间
- 1000~5000ms
- 内存
- 125MiB
- 难度
- 4
- 标签
- 递交数
- 2
- 已通过
- 0
- 上传者