?
# | Author | Problem | Lang | Verdict | Time | Memory | Sent | Judged | |
---|---|---|---|---|---|---|---|---|---|
77719406 |
Practice: AishwaryaR |
1234B2 - 27 | C++14 (GCC 6-32) | Accepted | 592 ms | 9796 KB | 2020-04-23 09:35:30 | 2020-04-23 09:35:30 |
//template by I_Love_Totoro, inspired by chamow //refer cook_book and AC of/Ubuntu folder _FunWithCP_ dated:21/04/2020- for POC and more insights respectively //interactive comments ahead! : for the love of CP <3 //note to self:for the love of everything good, uncomment fastread whenever applicable :) /* footnotes/ obs * */ /*main idea: * */ /*similar to: * */ /*re-learnt/ got better clarity * */ /*corollary * */ #include <bits/stdc++.h> #define pb push_back #define mp make_pair #define X first #define Y second #define rep(i,a,n) for(i=a;i<n;i++) #define repe(i,a,n) for(i=a;i<=n;i++) #define repn(i,a,n) for(i=n;i>=a;i--) #define all(x) (x).begin(),(x).end() #define PI (atan(1)*4) #define INF (int)1e9 #define fastread ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); //typedef vec vector<ll> typedef long long ll; typedef long double ld; typedef long int li; using namespace std; ll lcm(ll val1,ll val2) { if(val1==0||val2==0) return 0; else return (val1*val2)/__gcd(val1,val2); } ll pw(ll base,ll p) { if(base==1||p==0) return 1; if(p%2==0){ ll interm=pw(base,p/2); return interm*interm; } else return base*pw(base,p-1); } int main() { //fastread; /* freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); */ //cout << setprecision(10) << fixed << ll n,k,x; deque<ll>dq; map<ll,bool>m; cin>>n>>k; for (ll i = 0; i < n; i ++) { cin>>x; if (m[x]) continue; else { if (dq.size() < k) { dq.push_front(x); m[x] = 1; } else { ll p = dq.back(); m[p] = 0; dq.pop_back(); dq.push_front(x); m[x] = 1; } } } cout<<dq.size()<<"\n"; while(!dq.empty()) { cout<<dq.front()<<" "; dq.pop_front(); } cout<<"\n"; return 0; }
?
?
?
?