// Előzések.cpp : This file contains the 'main' function. Program execution begins and ends there.
//
#include <iostream>
#include <vector>
int find(int val, std::vector<int> vec)
{
int i = 0;
while (i < vec.size() && val != vec[i])
i++;
return i == vec.size() ? -1 : i;
}
int main()
{
int N, Q;
std::vector<int> sorrend;
std::vector<int> elozesrend;
std::cin >> N >> Q;
int* elozesek = new int[N];
for (int i = 0; i < N; i++)
{
int temp;
std::cin >> temp;
sorrend.push_back(temp);
elozesek[i] = 0;
}
for (int i = 0; i < Q; i++)
{
int temp;
std::cin >> temp;
elozesrend.push_back(temp);
}
int maxi = 0;
for (int i = 0; i < Q; i++)
{
//megelozi
int ind = find(elozesrend[i], sorrend);
int temp = sorrend[ind];
sorrend[ind] = sorrend[ind - 1];
sorrend[ind - 1] = temp;
int megelozott = sorrend[ind];
elozesek[megelozott]++;
if (elozesek[maxi] < elozesek[megelozott])
maxi = megelozott;
else if (elozesek[maxi] == elozesek[megelozott])
maxi = maxi > megelozott ? megelozott : maxi;
//valasz
std::cout << maxi << std::endl;
}
//delete[] elozesek;
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 3ms | 1968 KiB | ||||
subtask2 | 0/30 | ||||||
2 | Wrong answer | 3ms | 2092 KiB | ||||
3 | Accepted | 3ms | 2156 KiB | ||||
4 | Accepted | 4ms | 2060 KiB | ||||
5 | Accepted | 6ms | 2368 KiB | ||||
6 | Accepted | 8ms | 2664 KiB | ||||
7 | Accepted | 8ms | 2912 KiB | ||||
subtask3 | 0/70 | ||||||
8 | Accepted | 1.539s | 4472 KiB | ||||
9 | Time limit exceeded | 3.099s | 3724 KiB | ||||
10 | Time limit exceeded | 3.062s | 4180 KiB | ||||
11 | Time limit exceeded | 3.071s | 4524 KiB | ||||
12 | Time limit exceeded | 3.078s | 4836 KiB | ||||
13 | Time limit exceeded | 3.039s | 5740 KiB | ||||
14 | Time limit exceeded | 3.082s | 5924 KiB | ||||
15 | Time limit exceeded | 3.066s | 6368 KiB | ||||
16 | Time limit exceeded | 3.059s | 6288 KiB | ||||
17 | Time limit exceeded | 3.055s | 6228 KiB | ||||
18 | Time limit exceeded | 3.048s | 6420 KiB | ||||
19 | Time limit exceeded | 3.059s | 6368 KiB | ||||
20 | Time limit exceeded | 3.046s | 6568 KiB | ||||
21 | Time limit exceeded | 3.071s | 6704 KiB |