PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#CC0000026. Số không âm nhỏ nhất còn thiếu (Mex and Update)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Số không âm nhỏ nhất còn thiếu (Mex and Update)
Mex and Update
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
You have an array of non-negative integers. Each query replaces with . After each replacement, output the mex of the current array: the smallest non-negative integer absent from it. Updates persist.
Input
The first line contains ; the next line has the initial array values. Each of the next lines contains (one-based index ).
Output
Print the mex after each of the updates, one per line.
Subtasks
- Subtask 1 (20 points): ; ; .
- Subtask 2 (30 points): ; ; .
- Subtask 3 (50 points): ; ; .
Examples
Input
8 5
2 0 2 2 1 1 2 5
4 3
4 4
6 3
8 1000000000
2 1
Output
4
3
6
5
0
Explanation
The successive mex values are 4, 3, 6, 5, and 0. A very large value does not force the mex above n.