#include <iostream>
#include <vector>
#include <algorithm>
int main() {
int n, q;
std::cin >> n >> q;
std::vector<int> cars(n);
for (int i = 0; i < n; i++) {
std::cin >> cars[i];
}
std::vector<int> freq(n+1, 0);
int most_frequent = 1;
for (int i = 1; i < n; i++) {
if (cars[i] < cars[i-1]) {
std::swap(cars[i], cars[i-1]);
freq[cars[i]]++;
if (freq[cars[i]] > freq[most_frequent] || (freq[cars[i]] == freq[most_frequent] && cars[i] < most_frequent)) {
most_frequent = cars[i];
}
}
}
for (int i = 0; i < q; i++) {
int x;
std::cin >> x;
std::swap(cars[x-1], cars[x-2]);
freq[cars[x-1]]++;
freq[cars[x-2]]++;
if (freq[cars[x-1]] > freq[most_frequent] || (freq[cars[x-1]] == freq[most_frequent] && cars[x-1] < most_frequent)) {
most_frequent = cars[x-1];
}
if (freq[cars[x-2]] > freq[most_frequent] || (freq[cars[x-2]] == freq[most_frequent] && cars[x-2] < most_frequent)) {
most_frequent = cars[x-2];
}
std::cout << most_frequent << std::endl;
}
return 0;
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Runtime error | 3ms | 1792 KiB | ||||
subtask2 | 0/30 | ||||||
2 | Runtime error | 3ms | 2032 KiB | ||||
3 | Wrong answer | 3ms | 2056 KiB | ||||
4 | Wrong answer | 4ms | 2340 KiB | ||||
5 | Wrong answer | 4ms | 2472 KiB | ||||
6 | Wrong answer | 8ms | 2704 KiB | ||||
7 | Runtime error | 8ms | 3128 KiB | ||||
subtask3 | 0/70 | ||||||
8 | Wrong answer | 250ms | 3444 KiB | ||||
9 | Wrong answer | 201ms | 4028 KiB | ||||
10 | Wrong answer | 414ms | 4624 KiB | ||||
11 | Wrong answer | 277ms | 5368 KiB | ||||
12 | Wrong answer | 351ms | 5584 KiB | ||||
13 | Wrong answer | 277ms | 6188 KiB | ||||
14 | Wrong answer | 453ms | 7012 KiB | ||||
15 | Wrong answer | 456ms | 7192 KiB | ||||
16 | Wrong answer | 328ms | 7096 KiB | ||||
17 | Wrong answer | 564ms | 7224 KiB | ||||
18 | Wrong answer | 476ms | 7528 KiB | ||||
19 | Wrong answer | 234ms | 7624 KiB | ||||
20 | Wrong answer | 532ms | 7456 KiB | ||||
21 | Wrong answer | 522ms | 7580 KiB |