A12787 | Into Blocks (easy version)
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
This is an easier version of the next problem. In this version, $q = 0$ .
A sequence of integers is called nice if its elements are arranged in blocks like in $[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 $x$ to value $y$ , you must also change all other elements of value $x$ into $y$ as well. For example, for $[3, 3, 1, 3, 2, 1, 2]$ it isn't allowed to change first $1$ to $3$ and second $1$ to $2$ . You need to leave $1$ 's untouched or change them to the same value.
You are given a sequence of integers $a_1, a_2, \ldots, a_n$ and $q$ updates.
Each update is of form " $i$ $x$ " — change $a_i$ to $x$ . Updates are not independent (the change stays for the future).
Print the difficulty of the initial sequence and of the sequence after every update.
A sequence of integers is called nice if its elements are arranged in blocks like in $[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 $x$ to value $y$ , you must also change all other elements of value $x$ into $y$ as well. For example, for $[3, 3, 1, 3, 2, 1, 2]$ it isn't allowed to change first $1$ to $3$ and second $1$ to $2$ . You need to leave $1$ 's untouched or change them to the same value.
You are given a sequence of integers $a_1, a_2, \ldots, a_n$ and $q$ updates.
Each update is of form " $i$ $x$ " — change $a_i$ to $x$ . 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 $n$ and $q$ ( $1 \le n \le 200\,000$ , $q = 0$ ), the length of the sequence and the number of the updates.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ( $1 \le a_i \le 200\,000$ ), the initial sequence.
Each of the following $q$ lines contains integers $i_t$ and $x_t$ ( $1 \le i_t \le n$ , $1 \le x_t \le 200\,000$ ), the position and the new value for this position.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ( $1 \le a_i \le 200\,000$ ), the initial sequence.
Each of the following $q$ lines contains integers $i_t$ and $x_t$ ( $1 \le i_t \le n$ , $1 \le x_t \le 200\,000$ ), the position and the new value for this position.
输出格式
Print $q+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
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted