diff --git a/124-B2/SocialNetworkHard.cpp b/124-B2/SocialNetworkHard.cpp new file mode 100644 index 0000000..6263906 --- /dev/null +++ b/124-B2/SocialNetworkHard.cpp @@ -0,0 +1,45 @@ + #include + #define ll long long + + using namespace std; + + int main(void) + { + ll int n, k; + ll int id; + cin>>n>>k; + set s; + queue q; + + for(ll int i=0; i>id; + if(!s.count(id)){ + if(q.size()>=k) + { + ll int cur = q.front(); + q.pop(); + s.erase(cur); + } + s.insert(id); + q.push(id); + } + } + + vector res; + while(!q.empty()) + { + res.push_back(q.front()); + q.pop(); + } + + reverse(res.begin(), res.end()); + cout<