1
class TopVotedCandidate {
2
public:
3
vector<int> pref;
4
vector<int> glob_times;
5
TopVotedCandidate(vector<int> &persons, vector<int> &times) {
6
int n = times.size();
7
glob_times = times;
8
pref.resize(n);
9
vector<int> cnt;
10
int sz = persons.size();
11
cnt.resize(sz + 1, 0);
12
cnt[persons[0]]++;
13
pref[0] = persons[0];
14
int maxi = 1;
15
int maxi_person = persons[0];
16
for (int i = 1; i < n; i++) {
17
cnt[persons[i]]++;
18
if (cnt[persons[i]] > maxi) {
19
maxi = cnt[persons[i]];
20
maxi_person = persons[i];
21
} else if (cnt[persons[i]] == maxi) {
22
maxi_person = persons[i];
23
}
24

25
pref[i] = maxi_person;
26
}
27
}
28

29
int q(int t) {
30
int it = upper_bound(glob_times.begin(), glob_times.end(), t) - glob_times.begin();
31
if (it == 0) it++;
32
return pref[it - 1];
33
}
34
};
35

36
/**
37
* Your TopVotedCandidate object will be instantiated and called as such:
38
* TopVotedCandidate* obj = new TopVotedCandidate(persons, times);
39
* int param_1 = obj->q(t);
40
*/

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0