Блог пользователя salehin_076923

Автор salehin_076923, история, 10 месяцев назад, По-английски

Here is a simple problem made by me. Solve it & Give it a rating in comment section if you want.

Problem Name: Range Mex

You are given $$$n$$$ non-negative integers- $$$a_1,a_2,\ldots,a_n$$$. You have to find $$$mex_i$$$ for each $$$1\le i\leq n$$$ such that $$$mex_i$$$ is the mex of all numbers in the array except the $$$i-th$$$ number. e.g. if $$$a=$$${$$${2,5,0}$$$},

$$$mex_1 = mex(a_2,a_3)=mex(5,0)=1$$$

$$$mex_2 = mex(a_1,a_3)=mex(2,0)=1$$$

$$$mex_3 = mex(a_1,a_2)=mex(2,5)=0$$$

Input:

The first line contains a positive number $$$t (1\le t\le 10^4) - $$$ the number of test cases. The description of the test cases follows:

Each test case consists of 2 lines.

The first line contains a positive integer $$$n (1\le n\le 2\cdot 10^5) - $$$indicating the size of array $$$a$$$.

The second line contains $$$n$$$ non-negative integers $$$a_1,a_2,\ldots,a_n (0\le a_i\le 10^9) - $$$ the elements of the array $$$a$$$.

It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot10^5$$$.

Output:

For each test case, output $$$n$$$ integers- the $$$i-th$$$ of them indicating $$$mex_i$$$.(i.e. $$$mex_1, mex_2, mex_3,\ldots, mex_n)$$$

Examples:

Input:

5
0 1 2 3 4
5
1 0 2 5 9
2
1 2
3
1 0 2
4
4 7 0 1 

Output:

0 1 2 3 4 
1 0 2 3 3 
0 0 
1 0 2 
2 2 0 1 

Notes:

Here for the first test case,

$$$mex_1 = mex(1,2,3,4) = 0$$$

$$$mex_2 = mex(0,2,3,4) = 1$$$

$$$mex_3 = mex(0,1,3,4) = 2$$$

$$$mex_4 = mex(0,1,2,4) = 3$$$

$$$mex_5 = mex(0,1,2,3) = 4$$$

Solution
Code
  • Проголосовать: нравится
  • +6
  • Проголосовать: не нравится

»
10 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Auto comment: topic has been updated by salehin_076923 (previous revision, new revision, compare).

»
10 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

1000

»
10 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

900-1000, because can be easily implemented using frequency count and finding mex of the whole array.

»
10 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

900 , suitable for div 3 B or Div 4 C

»
10 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

800

»
10 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

This works right: Maintain a prefix and suffix of mex's! may be 800 ig

»
10 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

800, suitable for div.2 A