codeforces-scrape

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

713A.md (2884B)


      1 Source: https://codeforces.com/problemset/problem/713/A
      2 
      3 A. Sonya and Queries
      4 
      5 time limit per test
      6 
      7 1 second
      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 Today Sonya learned about long integers and invited all her friends to share the fun. Sonya has an initially empty multiset with integers. Friends give her *t* queries, each of one of the following type:
     22 
     23 1. +  *a**i* — add non-negative integer *a**i* to the multiset. Note, that she has a multiset, thus there may be many occurrences of the same integer.
     24 2. -  *a**i* — delete a single occurrence of non-negative integer *a**i* from the multiset. It's guaranteed, that there is at least one *a**i* in the multiset.
     25 3. ? *s* — count the number of integers in the multiset (with repetitions) that match some pattern *s* consisting of 0 and 1. In the pattern, 0 stands for the even digits, while 1 stands for the odd. Integer *x* matches the pattern *s*, if the parity of the *i*-th from the right digit in decimal notation matches the *i*-th from the right digit of the pattern. If the pattern is shorter than this integer, it's supplemented with 0-s from the left. Similarly, if the integer is shorter than the pattern its decimal notation is supplemented with the 0-s from the left.
     26 
     27 For example, if the pattern is *s* = 010, than integers 92, 2212, 50 and 414 match the pattern, while integers 3, 110, 25 and 1030 do not.
     28 
     29 Input
     30 
     31 The first line of the input contains an integer *t* (1 ≤ *t* ≤ 100 000) — the number of operation Sonya has to perform.
     32 
     33 Next *t* lines provide the descriptions of the queries in order they appear in the input file. The *i*-th row starts with a character *c**i* — the type of the corresponding operation. If *c**i* is equal to '+' or '-' then it's followed by a space and an integer *a**i* (0 ≤ *a**i* < 1018) given without leading zeroes (unless it's 0). If *c**i* equals '?' then it's followed by a space and a sequence of zeroes and onse, giving the pattern of length no more than 18.
     34 
     35 It's guaranteed that there will be at least one query of type '?'.
     36 
     37 It's guaranteed that any time some integer is removed from the multiset, there will be at least one occurrence of this integer in it.
     38 
     39 Output
     40 
     41 For each query of the third type print the number of integers matching the given pattern. Each integer is counted as many times, as it appears in the multiset at this moment of time.
     42 
     43 Examples
     44 
     45 Input
     46 
     47 ```
     48 12  
     49 + 1  
     50 + 241  
     51 ? 1  
     52 + 361  
     53 - 241  
     54 ? 0101  
     55 + 101  
     56 ? 101  
     57 - 101  
     58 ? 101  
     59 + 4000  
     60 ? 0
     61 ```
     62 
     63 Output
     64 
     65 ```
     66 2  
     67 1  
     68 2  
     69 1  
     70 1
     71 ```
     72 
     73 Input
     74 
     75 ```
     76 4  
     77 + 200  
     78 + 200  
     79 - 200  
     80 ? 0
     81 ```
     82 
     83 Output
     84 
     85 ```
     86 1
     87 ```
     88 
     89 Note
     90 
     91 Consider the integers matching the patterns from the queries of the third type. Queries are numbered in the order they appear in the input.
     92 
     93 1. 1 and 241.
     94 2. 361.
     95 3. 101 and 361.
     96 4. 361.
     97 5. 4000.