0911.cpp (584B)
1 class TopVotedCandidate { 2 map<int, int> um; 3 4 public: 5 TopVotedCandidate(const vector<int> &persons, const vector<int> ×) { 6 static int votes[5001]; 7 int maxi = 0, candid = 0; 8 9 memset(votes, 0x00, sizeof(votes)); 10 for (int i = 0; i < size(persons); i++) { 11 const int crnt = ++votes[persons[i]]; 12 13 if (crnt >= maxi) { 14 candid = persons[i]; 15 maxi = crnt; 16 } 17 18 um[times[i]] = candid; 19 } 20 } 21 22 int q(int t) const { return prev(um.upper_bound(t))->second; } 23 };