using
System;
using
System.Collections;
using
System.Collections.Generic;
using
System.Linq;
class
HelloWorld {
public
static
void
mostFrequent(
int
[] arr,
int
n,
int
m,
int
[][] q)
{
int
i = 0;
Dictionary<
int
,
int
> mp =
new
Dictionary<
int
,
int
>();
for
(i = 0; i < n; i++){
if
(!mp.ContainsKey(arr[i]))
mp.Add(arr[i], 1);
else
mp[arr[i]]++;
}
HashSet<KeyValuePair<
int
,
int
>> s =
new
HashSet<KeyValuePair<
int
,
int
>>();
foreach
(KeyValuePair<
int
,
int
> it
in
mp)
{
s.Add(
new
KeyValuePair<
int
,
int
>(-(it.Value), it.Key));
}
for
(i = 0; i < m; i++) {
int
j = q[i][0];
int
k = q[i][1];
if
(mp.ContainsKey(arr[j])){
s.Remove(
new
KeyValuePair<
int
,
int
> (-(mp[arr[j]]), arr[j]));
s.Add(
new
KeyValuePair<
int
,
int
> (-(mp[arr[j]]-1), arr[j]));
}
if
(mp.ContainsKey(arr[j])) mp[arr[j]]--;
if
(mp.ContainsKey(k)){
s.Remove(
new
KeyValuePair<
int
,
int
> (-(mp[k]), k));
s.Add(
new
KeyValuePair<
int
,
int
> (-((mp[k])+1), k));
}
if
(mp.ContainsKey(k)) mp[k]++;
else
mp.Add(k, 1);
arr[j] = k;
int
min_ele = (
int
)1e5;
int
res =0;
foreach
(
var
item
in
s) {
if
(min_ele > item.Key){
min_ele = item.Key;
res = item.Value;
}
}
Console.Write(res +
" "
);
}
}
static
void
Main() {
int
i = 0;
int
N = 5;
int
Q = 3;
int
[] arr = {2, 2, 2, 3, 3};
int
[][] query =
new
int
[][] {
new
int
[] {0, 3},
new
int
[] {4, 2},
new
int
[] {0, 4}
};
mostFrequent(arr, N, Q, query);
}
}