#include <bits/stdc++.h>
using namespace std;
int main(){
int n, q; cin >> n >> q;
vector<int> v(n+1, -1); // melyik autó hányadik helyen
vector<int> v2(n+1, -1); // melyik helyen hányadik autó
vector<int> el(n+1, 0); // kit hányszor eléőztek meg
int maxi = 0; // melyik autót előzték meg a legtöbbször
for (int i = 1; i <= n; i++){
int a; cin >> a; v[a] = i;
v2[i] = a;
}
for (int i = 0; i < q; i++){
int a; cin >> a;
int kit = v2[v[a]-1];
v[a] -= 1;
v[kit] += 1;
v2[v[a]] = a;
v2[v[kit]] = kit;
el[kit]++;
if (el[maxi] < el[kit]){
maxi = kit;
}
if (el[maxi] == el[kit] && kit < maxi){
maxi = kit;
}
cout << maxi << endl;
//for (int j : v2) cout << j << " ";
//cout << endl;
}
return 0;
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 3ms | 1808 KiB | ||||
subtask2 | 30/30 | ||||||
2 | Accepted | 3ms | 2056 KiB | ||||
3 | Accepted | 3ms | 2276 KiB | ||||
4 | Accepted | 4ms | 2532 KiB | ||||
5 | Accepted | 4ms | 2740 KiB | ||||
6 | Accepted | 4ms | 3088 KiB | ||||
7 | Accepted | 4ms | 3064 KiB | ||||
subtask3 | 70/70 | ||||||
8 | Accepted | 138ms | 4332 KiB | ||||
9 | Accepted | 202ms | 5300 KiB | ||||
10 | Accepted | 241ms | 5904 KiB | ||||
11 | Accepted | 275ms | 7028 KiB | ||||
12 | Accepted | 224ms | 7312 KiB | ||||
13 | Accepted | 273ms | 7808 KiB | ||||
14 | Accepted | 280ms | 8568 KiB | ||||
15 | Accepted | 483ms | 9304 KiB | ||||
16 | Accepted | 321ms | 9268 KiB | ||||
17 | Accepted | 375ms | 9264 KiB | ||||
18 | Accepted | 347ms | 9268 KiB | ||||
19 | Accepted | 312ms | 9268 KiB | ||||
20 | Accepted | 479ms | 8872 KiB | ||||
21 | Accepted | 458ms | 9544 KiB |