A Plus B Problem

시간 제한3초메모리 제한1024 MB

요약
두 개의 n자리 수를 더한 결과가 세 번째 행에 있고, 첫 두 행의 한 자리를 바꾸는 질의마다 합의 해당 자리와 이번 갱신으로 값이 바뀐 전체 자릿수를 구한다.
난이도

어려움10점 중 8점

유형
세그먼트 트리, 구현, 수학
정답자
아직 제출이 없습니다

문제

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×n3\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 nn digits even if the sum exceeds nn digits.

For example, when n=5n=5, the three rows can be "01234", "56789", "58023" or "56789", "58023", "14812".

To test your function, you are given qq queries. In the ii-th query, the c_ic\_i-th digit of the r_ir\_i-th row is updated to d_id\_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_ic\_i-th digit of the third row after the query and how many digits of the machine change in the query.

입력

The first line contains two integers nn and qq (1≤n,q≤1061\le n, q\le10^6).

The second line contains a string consisting of nn digits, representing the first row of the machine.

The third line contains a string consisting of nn digits, representing the second row of the machine.

There are qq lines in the following. The ii-th of the following line consists of three integers r_i,c_ir\_i, c\_i and d_id\_i (1≤r_i≤21\le r\_i \le 2, 1≤c_i≤n1\le c\_i\le n, 0≤d_i≤90\le d\_i\le 9).

출력

Output qq lines. In the ii-th line, output two integers - the c_ic\_i-th digit of the third row after the query and how many digits of the machine change in the query.

힌트

In the example, the initial rows are "01234", "56789", "58023".

After the 11-st query, the rows are "01234", "06789", "08023".

After the 22-nd query, the rows are "01234", "01789", "03023".

After the 33-th query, the rows are "01234", "01289", "02523".

After the 44-th query, the rows are "01234", "01239", "02473".

After the 55-th query, the rows are "01234", "01234", "02468".

예제1

  1. 예제 1

    입력
    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