标签:freopen algo lse stream ios string using scan name
using namespace std;
const LL N = 2e5 + 100;
LL n, k, a[N], tot, ans;
bool vis[N], cnt[N];
inline void open_judge() {
freopen ("page.in", "r", stdin);
freopen ("page.out", "w", stdout);
}
int main() {
open_judge();
scanf("%lld%lld",&n,&k);
for(int i = 1 ; i <= n ; i++)
scanf("%lld",&a[i]);
for (int i = 1 ; i <= n ; i++) {
if (cnt[a[i]])continue;
else if (tot < k)++ans, ++tot, cnt[a[i]] = true;
else {
memset(vis, false,sizeof(vis));
LL pos;
for(int j = i + 1 ; j <= n ; j++) {
if (vis[a[j]] || !cnt[a[j]]) continue;
pos = j;
vis[a[j]] = true;
}
for(int k = 1 ; k <= i ; k++) {
if(cnt[a[k]] && ! vis[a[k]])pos = k;
}
++ans;
cnt[a[pos]] = false;
cnt[a[i]] = true;
}
}
printf ("%lld\n", ans);
system("pause");
return 0;
}
标签:freopen algo lse stream ios string using scan name
原文地址:https://www.cnblogs.com/Repulser/p/11407594.html