408986: GYM103409 B A Plus B Problem

Memory Limit:0 MB Time Limit:0 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

B. A Plus B Problemtime limit per test3.0 smemory limit per test512 MBinputstandard inputoutputstandard output

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\times 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\le n, q\le10^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\le r_i \le 2$$$, $$$1\le c_i\le n$$$, $$$0\le d_i\le 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.

ExampleInput
5 5
01234
56789
2 1 0
2 2 1
2 3 2
2 4 3
2 5 4
Output
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".

加入题单

算法标签: