CF1920D.Array Repetition

普及+/提高

通过率:0%

时间限制:4.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Jayden has an array aa which is initially empty. There are nn operations of two types he must perform in the given order.

  1. Jayden appends an integer xx (1≤x≤n1 \leq x \leq n) to the end of array aa.
  2. Jayden appends xx copies of array aa to the end of array aa. In other words, array aa becomes [a,a,…,a⏟x][a,\underbrace{a,\ldots,a}_{x}]. It is guaranteed that he has done at least one operation of the first type before this.

Jayden has qq queries. For each query, you must tell him the kk-th element of array aa. The elements of the array are numbered from 11.

杰登有一个初始为空的数组 aa。他必须按给定顺序执行 nn 个操作,操作分为两类:

  1. 杰登将一个整数 xx(1≤x≤n1 \leq x \leq n)追加到数组 aa 的末尾;
  2. 杰登将 xx 份当前数组 aa 追加到 aa 的末尾。换言之,数组 aa 变为 [a,a,…,a⏟x][a,\underbrace{a,\ldots,a}_{x}]。保证在执行该操作前,至少已执行过一次第一类操作。

杰登有 qq 个查询。对每个查询,你需要告诉他数组 aa 的第 kk 个元素(数组元素编号从 11 开始)。

输入格式

Each test consists of multiple test cases. The first line contains a single integer tt (1≤t≤50001 \leq t \leq 5000) — the number of test cases. The description of the test cases follows.

The first line of each test case contains two integers nn and qq (1≤n,q≤1051 \leq n, q \leq 10^5) — the number of operations and the number of queries.

The following nn lines describe the operations. Each line contains two integers bb and xx (b∈1,2b \in {1, 2}), where bb denotes the type of operation. If b=1b=1, then xx (1≤x≤n1 \leq x \leq n) is the integer Jayden appends to the end of the array. If b=2b=2, then xx (1≤x≤1091 \leq x \leq 10^9) is the number of copies Jayden appends to the end of the array.

The next line of each test case contains qq integers k1,k2,…,kqk_1, k_2, \ldots, k_q (1≤ki≤min⁡(1018,c)1 \leq k_i \leq \min(10^{18}, c)), which denote the queries, where cc is the size of the array after finishing all nn operations.

It is guaranteed that the sum of nn and the sum of qq over all test cases does not exceed 10510^5.

每个测试包含多个测试用例。第一行包含一个整数 tt(1≤t≤50001 \leq t \leq 5000),表示测试用例的数量。随后是各测试用例的描述。

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

接下来的 nn 行描述操作。每行包含两个整数 bb 和 xx(b∈{1,2}b \in \{1, 2\}),其中 bb 表示操作类型:若 b=1b = 1,则 xx(1≤x≤n1 \leq x \leq n)是 Jayden 追加到数组末尾的整数;若 b=2b = 2,则 xx(1≤x≤1091 \leq x \leq 10^9)是 Jayden 追加到数组末尾的副本数量。

每个测试用例的下一行包含 qq 个整数 k1,k2,…,kqk_1, k_2, \ldots, k_q(1≤ki≤min⁡(1018,c)1 \leq k_i \leq \min(10^{18}, c)),表示查询,其中 cc 是执行完全部 nn 个操作后数组的大小。

保证所有测试用例中 nn 的总和与 qq 的总和均不超过 10510^5。

输出格式

For each test case, output qq integers — answers to Jayden's queries.

对于每个测试用例,输出 qq 个整数——即 Jayden 各个查询的答案。

输入输出样例

  • 输入#1

    4
    5 10
    1 1
    1 2
    2 1
    1 3
    2 3
    1 2 3 4 5 6 14 15 16 20
    10 10
    1 3
    1 8
    2 15
    1 6
    1 9
    1 1
    2 6
    1 1
    2 12
    2 10
    32752 25178 3198 3199 2460 2461 31450 33260 9016 4996
    12 5
    1 6
    1 11
    2 392130334
    1 4
    2 744811750
    1 10
    1 5
    2 209373780
    2 178928984
    1 3
    2 658326464
    2 1000000000
    914576963034536490 640707385283752918 636773368365261971 584126563607944922 1000000000000000000
    2 2
    1 1
    1 2
    1 2

    输出#1

    1 2 1 2 3 1 2 3 1 3
    9 8 1 3 1 3 6 3 8 8
    11 11 11 10 11
    1 2

说明/提示

In the first test case:

  • After the first operation a=[1]a = [1];
  • After the second operation a=[1,2]a = [1, 2];
  • After the third operation a=[1,2,1,2]a = [1, 2, 1, 2];
  • After the fourth operation a=[1,2,1,2,3]a = [1, 2, 1, 2, 3];
  • After the fifth operation a=[1,2,1,2,3,1,2,1,2,3,1,2,1,2,3,1,2,1,2,3]a = [1, 2, 1, 2, 3, 1, 2, 1, 2, 3, 1, 2, 1, 2, 3, 1, 2, 1, 2, 3].

In the fourth test case, after all operations a=[1,2]a = [1, 2].

在第一个测试用例中:

  • 第一次操作后,a=[1]a = [1];
  • 第二次操作后,a=[1,2]a = [1, 2];
  • 第三次操作后,a=[1,2,1,2]a = [1, 2, 1, 2];
  • 第四次操作后,a=[1,2,1,2,3]a = [1, 2, 1, 2, 3];
  • 第五次操作后,a=[1,2,1,2,3,1,2,1,2,3,1,2,1,2,3,1,2,1,2,3]a = [1, 2, 1, 2, 3, 1, 2, 1, 2, 3, 1, 2, 1, 2, 3, 1, 2, 1, 2, 3]。

在第四个测试用例中,所有操作完成后,a=[1,2]a = [1, 2]。

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

首页