-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCodeforces1234B2.cpp
More file actions
46 lines (43 loc) · 869 Bytes
/
Codeforces1234B2.cpp
File metadata and controls
46 lines (43 loc) · 869 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>
using namespace std;
typedef long long int ll;
#define mx 1000010
#define pb push_back
#define pf push_front
#define pp pop_back
#define speedforce ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
int main()
{
speedforce
ll i,j,t,k;
int n,m;
ll x;
map<ll,ll>a;
deque<ll>b;
a.clear();
b.clear();
scanf("%d %d",&n,&m);
for(i=0;i<n;i++)
{
scanf("%lld",&x);
if(!a[x])
{
b.pf(x);
if(b.size()>m)
{
int y=b.back();
a[y]=0;
b.pp();
}
a[x]=1;
}
}
int len=b.size();
printf("%d\n",len);
for(auto it=b.begin();it!=b.end();it++)
{
printf("%d ",*it);
}
printf("\n");
b.clear();
}