CF1209G1.Into Blocks (easy version)

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

This is an easier version of the next problem. In this version, q=0q = 0 .

A sequence of integers is called nice if its elements are arranged in blocks like in [3,3,3,4,1,1][3, 3, 3, 4, 1, 1] . Formally, if two elements are equal, everything in between must also be equal.

Let's define difficulty of a sequence as a minimum possible number of elements to change to get a nice sequence. However, if you change at least one element of value xx to value yy , you must also change all other elements of value xx into yy as well. For example, for [3,3,1,3,2,1,2][3, 3, 1, 3, 2, 1, 2] it isn't allowed to change first 11 to 33 and second 11 to 22 . You need to leave 11 's untouched or change them to the same value.

You are given a sequence of integers a1,a2,,ana_1, a_2, \ldots, a_n and qq updates.

Each update is of form " ii xx " — change aia_i to xx . Updates are not independent (the change stays for the future).

Print the difficulty of the initial sequence and of the sequence after every update.

输入格式

The first line contains integers nn and qq ( 1n2000001 \le n \le 200\,000 , q=0q = 0 ), the length of the sequence and the number of the updates.

The second line contains nn integers a1,a2,,ana_1, a_2, \ldots, a_n ( 1ai2000001 \le a_i \le 200\,000 ), the initial sequence.

Each of the following qq lines contains integers iti_t and xtx_t ( 1itn1 \le i_t \le n , 1xt2000001 \le x_t \le 200\,000 ), the position and the new value for this position.

输出格式

Print q+1q+1 integers, the answer for the initial sequence and the answer after every update.

输入输出样例

  • 输入#1

    5 0
    3 7 3 7 3
    

    输出#1

    2
    
  • 输入#2

    10 0
    1 2 1 2 3 1 1 1 50 1
    

    输出#2

    4
    
  • 输入#3

    6 0
    6 6 3 3 4 4
    

    输出#3

    0
    
  • 输入#4

    7 0
    3 3 1 3 2 1 2
    

    输出#4

    4
    
首页