#include <iostream>
#include <vector>
#include <unordered_map>
using namespace std;
int main() {
int n, q;
cin >> n >> q;
vector<int> cars(n);
for (int i = 0; i < n; i++) {
cin >> cars[i];
}
unordered_map<int, int> overtakes;
int leader = cars[0];
for (int i = 0; i < q; i++) {
int overtaken_car;
cin >> overtaken_car;
overtakes[cars[overtaken_car-1]]++;
if (overtakes[cars[overtaken_car-1]] > overtakes[leader] ||
(overtakes[cars[overtaken_car-1]] == overtakes[leader] && cars[overtaken_car-1] < leader)) {
leader = cars[overtaken_car-1];
}
cout << leader << endl;
}
return 0;
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Wrong answer | 3ms | 1688 KiB | ||||
subtask2 | 0/30 | ||||||
2 | Wrong answer | 3ms | 1928 KiB | ||||
3 | Wrong answer | 3ms | 2088 KiB | ||||
4 | Wrong answer | 4ms | 2372 KiB | ||||
5 | Wrong answer | 4ms | 2392 KiB | ||||
6 | Wrong answer | 6ms | 2760 KiB | ||||
7 | Wrong answer | 6ms | 2808 KiB | ||||
subtask3 | 0/70 | ||||||
8 | Wrong answer | 162ms | 5668 KiB | ||||
9 | Wrong answer | 365ms | 8408 KiB | ||||
10 | Wrong answer | 456ms | 9404 KiB | ||||
11 | Wrong answer | 222ms | 9488 KiB | ||||
12 | Wrong answer | 282ms | 10524 KiB | ||||
13 | Wrong answer | 481ms | 13772 KiB | ||||
14 | Wrong answer | 314ms | 14132 KiB | ||||
15 | Wrong answer | 395ms | 15232 KiB | ||||
16 | Wrong answer | 536ms | 15012 KiB | ||||
17 | Wrong answer | 405ms | 15452 KiB | ||||
18 | Wrong answer | 400ms | 15720 KiB | ||||
19 | Wrong answer | 229ms | 11620 KiB | ||||
20 | Wrong answer | 589ms | 15664 KiB | ||||
21 | Wrong answer | 370ms | 15292 KiB |