From cf4658639873d465edb32747b79f1a9acad9b4cb Mon Sep 17 00:00:00 2001 From: Sunidhibisht <57125949+Sunidhibisht@users.noreply.github.com> Date: Tue, 29 Oct 2019 12:26:30 +0530 Subject: [PATCH] Solution added. Added solution to the Div3 Codeforces Round #590. --- 124-B2/SocialNetworkHard.cpp | 45 ++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 124-B2/SocialNetworkHard.cpp 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<