How To Pass Memory Limit for this Solution

Revision en1, by nipul1, 2019-06-16 18:47:31

Problem //JSD #include<iostream> #include<set> #include<vector> #define ll long long #include<map> using namespace std; int main(){ int n,m,q,a; ios_base::sync_with_stdio(false); cin.tie(NULL); cin>>n>>m>>q; int Freq[m+1]={0}; for(int i=0;i<n;i++){ cin>>a; Freq[a]++; } int maa=0; for(int i=0;i<=m;i++){ maa=max(maa,Freq[i]); } vector<int > mpq[maa+1]; for(int i=1;i<=m;i++){ mpq[Freq[i]].push_back(i); } vector<int > ans; int count=0; set<int > s; for(ll i=0;i<=maa;i++){ for(auto x: mpq[i]){ s.insert(x); } for(auto x: s){ ans.push_back(x); } } while(q--){ ll p; cin>>p; p-=(n+1); if(p<ans.size()){ cout<<ans[p]; } else{ cout<<(p-ans.size())%m+1; } cout<<"\n"; } return 0; }

Tags #567(div 2), #data structure, #help

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en2 English nipul1 2019-06-16 18:56:01 230
en1 English nipul1 2019-06-16 18:47:31 888 Initial revision (published)