CF1791F.Range Update Point Query
普及/提高-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Given an array a1,a2,…,an, you need to handle a total of q updates and queries of two types:
- 1 l r — for each index i with l≤i≤r, update the value of ai to the sum of the digits of ai.
- 2 x — output ax.
给定一个数组 a1,a2,…,an,你需要处理总共 q 个更新与查询操作,操作分为两类:
- 1 l r — 对每个满足 l≤i≤r 的下标 i,将 ai 的值更新为 ai 的各位数字之和。
- 2 x — 输出 ax。
输入格式
The first line of the input contains an integer t (1≤t≤1000) — the number of testcases.
The first line of each test case contains two integers n and q (1≤n,q≤2⋅105) — the size of the array and the number of queries, respectively.
The second line of each test case contains n integers a1,a2,…,an (1≤ai≤109).
The next q lines of each test case are of two forms:
- 1 l r (1≤l≤r≤n) — it means, for each index i with l≤i≤r, you should update the value of ai to the sum of its digits.
- 2 x (1≤x≤n) — it means you should output ax.
There is at least one query of the second type.
The sum of n over all test cases does not exceed 2⋅105.
The sum of q over all test cases does not exceed 2⋅105.
输入的第一行包含一个整数 t(1≤t≤1000),表示测试用例的数量。
每个测试用例的第一行包含两个整数 n 和 q(1≤n,q≤2⋅105),分别表示数组的大小和查询的数量。
每个测试用例的第二行包含 n 个整数 a1,a2,…,an(1≤ai≤109)。
每个测试用例接下来的 q 行为以下两种形式之一:
- 1 l r(1≤l≤r≤n)—— 表示对每个满足 l≤i≤r 的下标 i,将 ai 更新为其各位数字之和;
- 2 x(1≤x≤n)—— 表示输出 ax 的值。
保证每个测试用例中至少存在一个类型为 2 的查询。
所有测试用例的 n 之和不超过 2⋅105。
所有测试用例的 q 之和不超过 2⋅105。
输出格式
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,6,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,6,6,12,7].
- We are queried for x=1, x=3, and x=5, and output 1, 6, and 7.
在第一个测试用例中,发生如下过程:
- 初始时,a=[1,420,69,1434,2023]。
- 对 l=2、r=3 执行操作,得到 [1,6,15,1434,2023]。
- 查询 x=2、x=3 和 x=4,输出结果为 6、15 和 1434。
- 对 l=2、r=5 执行操作,得到 [1,6,6,12,7]。
- 查询 x=1、x=3 和 x=5,输出结果为 1、6 和 7。
输入解题思路,AI测评打分。不知道怎么写?