P9297 [POI 2020/2021 R1] Licznik długu / Debt Counter
Background
**This problem is translated from [XXVIII Olimpiada Informatyczna – Stage I](https://sio2.mimuw.edu.pl/c/oi28-1/dashboard/) [Licznik długu](https://sio2.mimuw.edu.pl/c/oi28-1/p/lic/).**
Description
Professor Bajterowicz points out that the economic situation of Bajtocja is not optimistic right now. To warn the public, he asked the Bajtazara company to install a large display in the city center of Bajtocja’s capital, used to show the current public debt of Bajtocja.
Bajtocja’s public debt consists of two parts: domestic debt and international debt. The domestic debt and the international debt can each have at most $n-1$ decimal digits. The display shows the sum of these two debts.
As time passes, Bajtocja’s debt situation keeps changing. You now need to help the Bajtazara company complete the editing of the display software.
The software needs to perform the following three operations:
- Change the digit at a certain position of the domestic debt.
- Change the digit at a certain position of the international debt.
- Output the digit at a certain position of the total public debt.
Input Format
The first line contains two integers $n, z$, representing the number of digits the display can show and the number of operations.
The second line contains a number of length $n-1$, representing the initial value of Bajtocja’s domestic debt. This number may have leading zeros.
The third line contains a number of length $n-1$, representing the initial value of Bajtocja’s international debt. This number may have leading zeros.
The next $z$ lines each describe an operation:
- $\texttt{W}\ i \ c$ means changing the $i$-th digit of the domestic debt to $c$ ($1 \leq i \leq n-1$, $0 \leq c \leq 9$).
- $\texttt{Z}\ i \ c$ means changing the $i$-th digit of the international debt to $c$ ($1 \leq i \leq n-1$, $0 \leq c \leq 9$).
- $\texttt{S}\ i$ means outputting the value of the $i$-th digit of the total public debt ($1 \leq i \leq n-1$).
Output Format
For each $\texttt{S}$ operation, output one line with one integer representing the answer.
Explanation/Hint
[Sample Explanation #1]:
Initially, the total public debt is $7341+150=7491$, so the value of the third digit is $4$.
After operation $2$, the total public debt is $7041+150=7191$, so the value of the third digit is $1$.
After operation $4$, the total public debt is $7041+159=7200$, so the value of the first digit is $0$, and the value of the third digit is $2$.
[Constraints]:
All testdata satisfy: $2 \leq n \leq 10^5$, $1 \leq z \leq 10^5$.
|Subtask ID|Constraint|Points|
|:-:|:-:|:-:|
|$1$|$n, z \leq 5 \times 10^3$|$30$|
|$2$|At any time, every digit of the domestic debt and the international debt is either $0$ or $5$|$20$|
|$3$|No additional constraints|$50$|
Translated by ChatGPT 5