#include<iostream>#include<vector>#include<algorithm>#include<map>classTopVotedCandidate{public:TopVotedCandidate(std::vector<int>&persons,std::vector<int>×){intn=persons.size();tops.resize(n);times_=times;std::unordered_map<int,int>votes;inttop=-1;for(inti=0;i<n;++i){++votes[persons[i]];if(votes[persons[i]]>=votes[top]){top=persons[i];}tops[i]=top;}}intq(intt){autoit=std::lower_bound(times_.begin(),times_.end(),t+1);if(it==times_.begin()){returntops[0];}returntops[it-times_.begin()-1];}private:std::vector<int>tops;std::vector<int>times_;};/**
* Your TopVotedCandidate object will be instantiated and called as such:
* TopVotedCandidate* obj = new TopVotedCandidate(persons, times);
* int param_1 = obj->q(t);
*/