A15704 | Range Update Point Query
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Given an array $a_1, a_2, \dots, a_n$ , you need to handle a total of $q$ updates and queries of two types:
- $1$ $l$ $r$ — for each index $i$ with $l \leq i \leq r$ , update the value of $a_i$ to the sum of the digits of $a_i$ .
- $2$ $x$ — output $a_x$ .
- $1$ $l$ $r$ — for each index $i$ with $l \leq i \leq r$ , update the value of $a_i$ to the sum of the digits of $a_i$ .
- $2$ $x$ — output $a_x$ .
输入格式
The first line of the input contains an integer $t$ ( $1 \leq t \leq 1000$ ) — the number of testcases.
The first line of each test case contains two integers $n$ and $q$ ( $1 \le n, q \le 2 \cdot 10^5$ ) — the size of the array and the number of queries, respectively.
The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ( $1 \le a_i \le 10^9$ ).
The next $q$ lines of each test case are of two forms:
- $1$ $l$ $r$ ( $1 \leq l \leq r \leq n$ ) — it means, for each index $i$ with $l \leq i \leq r$ , you should update the value of $a_i$ to the sum of its digits.
- $2$ $x$ ( $1 \leq x \leq n$ ) — it means you should output $a_x$ .
There is at least one query of the second type.
The sum of $n$ over all test cases does not exceed $2 \cdot 10^5$ .
The sum of $q$ over all test cases does not exceed $2 \cdot 10^5$ .
The first line of each test case contains two integers $n$ and $q$ ( $1 \le n, q \le 2 \cdot 10^5$ ) — the size of the array and the number of queries, respectively.
The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ( $1 \le a_i \le 10^9$ ).
The next $q$ lines of each test case are of two forms:
- $1$ $l$ $r$ ( $1 \leq l \leq r \leq n$ ) — it means, for each index $i$ with $l \leq i \leq r$ , you should update the value of $a_i$ to the sum of its digits.
- $2$ $x$ ( $1 \leq x \leq n$ ) — it means you should output $a_x$ .
There is at least one query of the second type.
The sum of $n$ over all test cases does not exceed $2 \cdot 10^5$ .
The sum of $q$ over all test cases does not exceed $2 \cdot 10^5$ .
输出格式
For each test case, output the answers of queries of the second type, in the order they are given.
输入输出样例
输入 #1
3 5 8 1 420 69 1434 2023 1 2 3 2 2 2 3 2 4 1 2 5 2 1 2 3 2 5 2 3 9999 1000 1 1 2 2 1 2 2 1 1 1 2 1
输出 #1
6 15 1434 1 6 7 36 1 1
In the first test case, the following process occurs:
- Initially, $a = [1, 420, 69, 1434, 2023]$ .
- The operation is performed for $l=2$ , $r=3$ , yielding $[1, \textcolor{red}{6}, \textcolor{red}{15}, 1434, 2023]$ .
- We are queried for $x=2$ , $x=3$ , and $x=4$ , and output $6$ , $15$ , and $1434$ .
- The operation is performed for $l=2$ , $r=5$ , yielding $[1, \textcolor{red}{6}, \textcolor{red}{6}, \textcolor{red}{12}, \textcolor{red}{7}]$ .
- We are queried for $x=1$ , $x=3$ , and $x=5$ , and output $1$ , $6$ , and $7$ .
- Initially, $a = [1, 420, 69, 1434, 2023]$ .
- The operation is performed for $l=2$ , $r=3$ , yielding $[1, \textcolor{red}{6}, \textcolor{red}{15}, 1434, 2023]$ .
- We are queried for $x=2$ , $x=3$ , and $x=4$ , and output $6$ , $15$ , and $1434$ .
- The operation is performed for $l=2$ , $r=5$ , yielding $[1, \textcolor{red}{6}, \textcolor{red}{6}, \textcolor{red}{12}, \textcolor{red}{7}]$ .
- We are queried for $x=1$ , $x=3$ , and $x=5$ , and output $1$ , $6$ , and $7$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted