570C.md (2899B)
1 Source: https://codeforces.com/problemset/problem/570/C 2 3 C. Replacement 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 Daniel has a string *s*, consisting of lowercase English letters and period signs (characters '.'). Let's define the operation of replacement as the following sequence of steps: find a substring ".." (two consecutive periods) in string *s*, of all occurrences of the substring let's choose the first one, and replace this substring with string ".". In other words, during the replacement operation, the first two consecutive periods are replaced by one. If string *s* contains no two consecutive periods, then nothing happens. 22 23 Let's define *f*(*s*) as the minimum number of operations of replacement to perform, so that the string does not have any two consecutive periods left. 24 25 You need to process *m* queries, the *i*-th results in that the character at position *x**i* (1 ≤ *x**i* ≤ *n*) of string *s* is assigned value *c**i*. After each operation you have to calculate and output the value of *f*(*s*). 26 27 Help Daniel to process all queries. 28 29 Input 30 31 The first line contains two integers *n* and *m* (1 ≤ *n*, *m* ≤ 300 000) the length of the string and the number of queries. 32 33 The second line contains string *s*, consisting of *n* lowercase English letters and period signs. 34 35 The following *m* lines contain the descriptions of queries. The *i*-th line contains integer *x**i* and *c**i* (1 ≤ *x**i* ≤ *n*, *c**i* — a lowercas English letter or a period sign), describing the query of assigning symbol *c**i* to position *x**i*. 36 37 Output 38 39 Print *m* numbers, one per line, the *i*-th of these numbers must be equal to the value of *f*(*s*) after performing the *i*-th assignment. 40 41 Examples 42 43 Input 44 45 ``` 46 10 3 47 .b..bz.... 48 1 h 49 3 c 50 9 f 51 ``` 52 53 Output 54 55 ``` 56 4 57 3 58 1 59 ``` 60 61 Input 62 63 ``` 64 4 4 65 .cc. 66 2 . 67 3 . 68 2 a 69 1 a 70 ``` 71 72 Output 73 74 ``` 75 1 76 3 77 1 78 1 79 ``` 80 81 Note 82 83 Note to the first sample test (replaced periods are enclosed in square brackets). 84 85 The original string is ".b..bz....". 86 87 * after the first query *f*(hb..bz....) = 4 ("hb[..]bz...." → "hb.bz[..].." → "hb.bz[..]." → "hb.bz[..]" → "hb.bz.") 88 * after the second query *f*(hbс.bz....) = 3 ("hbс.bz[..].." → "hbс.bz[..]." → "hbс.bz[..]" → "hbс.bz.") 89 * after the third query *f*(hbс.bz..f.) = 1 ("hbс.bz[..]f." → "hbс.bz.f.") 90 91 Note to the second sample test. 92 93 The original string is ".cc.". 94 95 * after the first query: *f*(..c.) = 1 ("[..]c." → ".c.") 96 * after the second query: *f*(....) = 3 ("[..].." → "[..]." → "[..]" → ".") 97 * after the third query: *f*(.a..) = 1 (".a[..]" → ".a.") 98 * after the fourth query: *f*(aa..) = 1 ("aa[..]" → "aa.")