-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1700.cpp
More file actions
46 lines (40 loc) · 926 Bytes
/
1700.cpp
File metadata and controls
46 lines (40 loc) · 926 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define ll long long
using namespace std;
const ll INF = 1e9 + 7;
const ll DIV = 987654321;
int n, k;
int arr[101];
int inq[101];
set<pair<int,int>> st;
int main()
{
fastio;
cin >> n >> k;
for(int i =0 ;i < k;i++){
cin >> arr[i];
}
int ans = 0;
memset(inq, -1, sizeof inq);
for(int i =0 ;i < k;i++){
int j = i + 1;
for(;j < k && arr[j] != arr[i];j++);
if(inq[arr[i]] != -1){
st.erase({inq[arr[i]], arr[i]});
st.insert({j, arr[i]});
inq[arr[i]] = j;
continue;
}
if(st.size() == n){
ans++;
auto[a, b] = *(--st.end());
inq[b] = -1;
st.erase(--st.end());
}
inq[arr[i]]=j;
st.insert({j, arr[i]});
}
cout << ans;
return 0;
}