CF1791F.Range Update Point Query

普及/提高-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Given an array a1,a2,…,ana_1, a_2, \dots, a_n, you need to handle a total of qq updates and queries of two types:

  • 11 ll rr — for each index ii with l≤i≤rl \leq i \leq r, update the value of aia_i to the sum of the digits of aia_i.
  • 22 xx — output axa_x.

给定一个数组 a1,a2,…,ana_1, a_2, \dots, a_n,你需要处理总共 qq 个更新与查询操作,操作分为两类:

  • 11 ll rr — 对每个满足 l≤i≤rl \leq i \leq r 的下标 ii,将 aia_i 的值更新为 aia_i 的各位数字之和。
  • 22 xx — 输出 axa_x。

输入格式

The first line of the input contains an integer tt (1≤t≤10001 \leq t \leq 1000) — the number of testcases.

The first line of each test case contains two integers nn and qq (1≤n,q≤2⋅1051 \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 nn integers a1,a2,…,ana_1, a_2, \dots, a_n (1≤ai≤1091 \le a_i \le 10^9).

The next qq lines of each test case are of two forms:

  • 11 ll rr (1≤l≤r≤n1 \leq l \leq r \leq n) — it means, for each index ii with l≤i≤rl \leq i \leq r, you should update the value of aia_i to the sum of its digits.
  • 22 xx (1≤x≤n1 \leq x \leq n) — it means you should output axa_x.

There is at least one query of the second type.

The sum of nn over all test cases does not exceed 2⋅1052 \cdot 10^5.

The sum of qq over all test cases does not exceed 2⋅1052 \cdot 10^5.

输入的第一行包含一个整数 tt(1≤t≤10001 \leq t \leq 1000),表示测试用例的数量。

每个测试用例的第一行包含两个整数 nn 和 qq(1≤n,q≤2⋅1051 \leq n, q \leq 2 \cdot 10^5),分别表示数组的大小和查询的数量。

每个测试用例的第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \dots, a_n(1≤ai≤1091 \leq a_i \leq 10^9)。

每个测试用例接下来的 qq 行为以下两种形式之一:

  • 11 ll rr(1≤l≤r≤n1 \leq l \leq r \leq n)—— 表示对每个满足 l≤i≤rl \leq i \leq r 的下标 ii,将 aia_i 更新为其各位数字之和;
  • 22 xx(1≤x≤n1 \leq x \leq n)—— 表示输出 axa_x 的值。

保证每个测试用例中至少存在一个类型为 2 的查询。

所有测试用例的 nn 之和不超过 2⋅1052 \cdot 10^5。

所有测试用例的 qq 之和不超过 2⋅1052 \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]a = [1, 420, 69, 1434, 2023].
  • The operation is performed for l=2l=2, r=3r=3, yielding [1,6,15,1434,2023][1, \color{red}{6}, \color{red}{15}, 1434, 2023].
  • We are queried for x=2x=2, x=3x=3, and x=4x=4, and output 66, 1515, and 14341434.
  • The operation is performed for l=2l=2, r=5r=5, yielding [1,6,6,12,7][1, \color{red}{6}, \color{red}{6}, \color{red}{12}, \color{red}{7}].
  • We are queried for x=1x=1, x=3x=3, and x=5x=5, and output 11, 66, and 77.

在第一个测试用例中,发生如下过程:

  • 初始时,a=[1,420,69,1434,2023]a = [1, 420, 69, 1434, 2023]。
  • 对 l=2l=2、r=3r=3 执行操作,得到 [1,6,15,1434,2023][1, \color{red}{6}, \color{red}{15}, 1434, 2023]。
  • 查询 x=2x=2、x=3x=3 和 x=4x=4,输出结果为 66、1515 和 14341434。
  • 对 l=2l=2、r=5r=5 执行操作,得到 [1,6,6,12,7][1, \color{red}{6}, \color{red}{6}, \color{red}{12}, \color{red}{7}]。
  • 查询 x=1x=1、x=3x=3 和 x=5x=5,输出结果为 11、66 和 77。

输入解题思路,AI测评打分。不知道怎么写?

首页