#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 max_overtakes = 0, most_overtaken = -1;
for (int i = 0; i < q; i++) {
int overtaken_car;
cin >> overtaken_car;
int overtaking_car = cars[overtaken_car-2];
overtakes[overtaking_car]++;
if (overtakes[overtaking_car] > max_overtakes ||
(overtakes[overtaking_car] == max_overtakes && overtaking_car < most_overtaken)) {
max_overtakes = overtakes[overtaking_car];
most_overtaken = overtaking_car;
}
cars.erase(cars.begin() + overtaken_car - 1);
cars.insert(cars.begin() + overtaken_car - 2, overtaking_car);
cout << most_overtaken << endl;
}
return 0;
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Wrong answer | 3ms | 1684 KiB | ||||
subtask2 | 0/30 | ||||||
2 | Wrong answer | 3ms | 1932 KiB | ||||
3 | Wrong answer | 3ms | 2056 KiB | ||||
4 | Wrong answer | 4ms | 2168 KiB | ||||
5 | Wrong answer | 4ms | 2312 KiB | ||||
6 | Wrong answer | 6ms | 2668 KiB | ||||
7 | Wrong answer | 8ms | 2624 KiB | ||||
subtask3 | 0/70 | ||||||
8 | Wrong answer | 533ms | 4172 KiB | ||||
9 | Wrong answer | 1.328s | 6236 KiB | ||||
10 | Wrong answer | 1.843s | 6948 KiB | ||||
11 | Wrong answer | 1.481s | 8872 KiB | ||||
12 | Wrong answer | 2.039s | 9272 KiB | ||||
13 | Time limit exceeded | 3.026s | 10036 KiB | ||||
14 | Time limit exceeded | 3.055s | 6536 KiB | ||||
15 | Time limit exceeded | 3.072s | 6468 KiB | ||||
16 | Time limit exceeded | 3.061s | 6648 KiB | ||||
17 | Time limit exceeded | 3.069s | 6788 KiB | ||||
18 | Time limit exceeded | 3.069s | 6748 KiB | ||||
19 | Wrong answer | 2.447s | 10540 KiB | ||||
20 | Time limit exceeded | 3.033s | 6880 KiB | ||||
21 | Time limit exceeded | 3.071s | 7024 KiB |