The 2021 CCPC Guilin Onsite
China, Guilin, November, 07, 2021
Problem B. A Plus B Problem
Input file: standard input
Output file: standard output
Time limit: 3 seconds
Memory limit: 512 megabytes
JB gets a machine that can solve “A Plus B Problem” and feels curious about the mechanism. He hears
that you are proficient in competitive programming and have learned many advanced data structures and
algorithms such as Link-Cut tree, Lagrange Inversion formula, Sweepline Mo, and so on. Hence, he asks
you to help implement a program that can solve “A Plus B Problem” as same as the machine.
The machine consists of 3 × n digits. The digits of the first two rows can be changed arbitrarily, and the
third row always equals the decimal sum of the first two rows. The third row only consists of the lowest
n digits even if the sum exceeds n digits.
For example, when n = 5, the three rows can be “01234”, “56789”, “58023” or “56789”, “58023”, “14812”.
To test your function, you are given q queries. In the i-th query, the c
i
-th digit of the r
i
-th row is updated
to d
i
(the digit may not change). Because the digits are too many and JB has no time to check your
answer, he only asks you to find the c
i
-th digit of the third row after the query and how many digits of
the machine change in the query.
Input
The first line contains two integers n and q (1 ≤ n, q ≤ 10
6
).
The second line contains a string consisting of n digits, representing the first row of the machine.
The third line contains a string consisting of n digits, representing the second row of the machine.
There are q lines in the following. The i-th of the following line consists of three integers r
i
, c
i
and d
i
(1 ≤ r
i
≤ 2, 1 ≤ c
i
≤ n, 0 ≤ d
i
≤ 9).
Output
Output q lines. In the i-th line, output two integers - the c
i
-th digit of the third row after the query and
how many digits of the machine change in the query.
Example
standard input standard output
5 5
01234
56789
2 1 0
2 2 1
2 3 2
2 4 3
2 5 4
0 2
3 2
5 3
7 3
8 3
Note
In the example, the initial rows are “01234”, “56789”, “58023”.
After the 1-st query, the rows are “01234”, “06789”, “08023”.
After the 2-nd query, the rows are “01234”, “01789”, “03023”.
After the 3-th query, the rows are “01234”, “01289”, “02523”.
After the 4-th query, the rows are “01234”, “01239”, “02473”.
After the 5-th query, the rows are “01234”, “01234”, “02468”.
Page 3 of 15