codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

1841B.md (3355B)


      1 Source: https://codeforces.com/problemset/problem/1841/B
      2 
      3 B. Keep it Beautiful
      4 
      5 time limit per test
      6 
      7 2 seconds
      8 
      9 memory limit per test
     10 
     11 512 megabytes
     12 
     13 input
     14 
     15 standard input
     16 
     17 output
     18 
     19 standard output
     20 
     21 The array $[a_1, a_2, \dots, a_k]$ is called beautiful if it is possible to remove several (maybe zero) elements from the beginning of the array and insert all these elements to the back of the array in the same order in such a way that the resulting array is sorted in non-descending order.
     22 
     23 In other words, the array $[a_1, a_2, \dots, a_k]$ is beautiful if there exists an integer $i \in [0, k-1]$ such that the array $[a_{i+1}, a_{i+2}, \dots, a_{k-1}, a_k, a_1, a_2, \dots, a_i]$ is sorted in non-descending order.
     24 
     25 For example:
     26 
     27 * $[3, 7, 7, 9, 2, 3]$ is beautiful: we can remove four first elements and insert them to the back in the same order, and we get the array $[2, 3, 3, 7, 7, 9]$, which is sorted in non-descending order;
     28 * $[1, 2, 3, 4, 5]$ is beautiful: we can remove zero first elements and insert them to the back, and we get the array $[1, 2, 3, 4, 5]$, which is sorted in non-descending order;
     29 * $[5, 2, 2, 1]$ is not beautiful.
     30 
     31 Note that any array consisting of zero elements or one element is beautiful.
     32 
     33 You are given an array $a$, which is initially empty. You have to process $q$ queries to it. During the $i$-th query, you will be given one integer $x_i$, and you have to do the following:
     34 
     35 * if you can append the integer $x_i$ to the back of the array $a$ so that the array $a$ stays beautiful, you have to append it;
     36 * otherwise, do nothing.
     37 
     38 After each query, report whether you appended the given integer $x_i$, or not.
     39 
     40 Input
     41 
     42 The first line contains one integer $t$ ($1 \le t \le 10^4$) — the number of test cases.
     43 
     44 Each test case consists of two lines. The first line contains one integer $q$ ($1 \le q \le 2 \cdot 10^5$) — the number of queries. The second line contains $q$ integers $x_1, x_2, \dots, x_q$ ($0 \le x_i \le 10^9$).
     45 
     46 Additional constraint on the input: the sum of $q$ over all test cases does not exceed $2 \cdot 10^5$).
     47 
     48 Output
     49 
     50 For each test case, print one string consisting of exactly $q$ characters. The $i$-th character of the string should be 1 if you appended the integer during the $i$-th query; otherwise, it should be 0.
     51 
     52 Example
     53 
     54 Input
     55 
     56 ```
     57 3
     58 
     59 9
     60 
     61 3 7 7 9 2 4 6 3 4
     62 
     63 5
     64 
     65 1 1 1 1 1
     66 
     67 5
     68 
     69 3 2 1 2 3
     70 ```
     71 
     72 Output
     73 
     74 ```
     75 111110010
     76 11111
     77 11011
     78 ```
     79 
     80 Note
     81 
     82 Consider the first test case of the example. Initially, the array is $[]$.
     83 
     84 * trying to append an integer $3$. The array $[3]$ is beautiful, so we append $3$;
     85 * trying to append an integer $7$. The array $[3, 7]$ is beautiful, so we append $7$;
     86 * trying to append an integer $7$. The array $[3, 7, 7]$ is beautiful, so we append $7$;
     87 * trying to append an integer $9$. The array $[3, 7, 7, 9]$ is beautiful, so we append $9$;
     88 * trying to append an integer $2$. The array $[3, 7, 7, 9, 2]$ is beautiful, so we append $2$;
     89 * trying to append an integer $4$. The array $[3, 7, 7, 9, 2, 4]$ is not beautiful, so we don't append $4$;
     90 * trying to append an integer $6$. The array $[3, 7, 7, 9, 2, 6]$ is not beautiful, so we don't append $6$;
     91 * trying to append an integer $3$. The array $[3, 7, 7, 9, 2, 3]$ is beautiful, so we append $3$;
     92 * trying to append an integer $4$. The array $[3, 7, 7, 9, 2, 3, 4]$ is not beautiful, so we don't append $4$.