codeforces-scrape

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

982B.md (2570B)


      1 Source: https://codeforces.com/problemset/problem/982/B
      2 
      3 B. Bus of Characters
      4 
      5 time limit per test
      6 
      7 2 seconds
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 standard input
     16 
     17 output
     18 
     19 standard output
     20 
     21 In the Bus of Characters there are $n$ rows of seat, each having $2$ seats. The width of both seats in the $i$-th row is $w_i$ centimeters. All integers $w_i$ are distinct.
     22 
     23 Initially the bus is empty. On each of $2n$ stops one passenger enters the bus. There are two types of passengers:
     24 
     25 * an introvert always chooses a row where both seats are empty. Among these rows he chooses the one with the smallest seats width and takes one of the seats in it;
     26 * an extrovert always chooses a row where exactly one seat is occupied (by an introvert). Among these rows he chooses the one with the largest seats width and takes the vacant place in it.
     27 
     28 You are given the seats width in each row and the order the passengers enter the bus. Determine which row each passenger will take.
     29 
     30 Input
     31 
     32 The first line contains a single integer $n$ ($1 \le n \le 200\,000$) — the number of rows in the bus.
     33 
     34 The second line contains the sequence of integers $w_1, w_2, \dots, w_n$ ($1 \le w_i \le 10^{9}$), where $w_i$ is the width of each of the seats in the $i$-th row. It is guaranteed that all $w_i$ are distinct.
     35 
     36 The third line contains a string of length $2n$, consisting of digits '0' and '1' — the description of the order the passengers enter the bus. If the $j$-th character is '0', then the passenger that enters the bus on the $j$-th stop is an introvert. If the $j$-th character is '1', the the passenger that enters the bus on the $j$-th stop is an extrovert. It is guaranteed that the number of extroverts equals the number of introverts (i. e. both numbers equal $n$), and for each extrovert there always is a suitable row.
     37 
     38 Output
     39 
     40 Print $2n$ integers — the rows the passengers will take. The order of passengers should be the same as in input.
     41 
     42 Examples
     43 
     44 Input
     45 
     46 ```
     47 2  
     48 3 1  
     49 0011
     50 ```
     51 
     52 Output
     53 
     54 ```
     55 2 1 1 2
     56 ```
     57 
     58 Input
     59 
     60 ```
     61 6  
     62 10 8 9 11 13 5  
     63 010010011101
     64 ```
     65 
     66 Output
     67 
     68 ```
     69 6 6 2 3 3 1 4 4 1 2 5 5
     70 ```
     71 
     72 Note
     73 
     74 In the first example the first passenger (introvert) chooses the row $2$, because it has the seats with smallest width. The second passenger (introvert) chooses the row $1$, because it is the only empty row now. The third passenger (extrovert) chooses the row $1$, because it has exactly one occupied seat and the seat width is the largest among such rows. The fourth passenger (extrovert) chooses the row $2$, because it is the only row with an empty place.