CF1737G.Ela Takes Dancing Class

NOI/NOI+/CTSC

通过率:0%

时间限制:4.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

DTL engineers love partying in the weekend. Ela does, too! Unfortunately, she didn't know how to dance yet. Therefore, she decided to take a dancing class.

There are nn students in the dancing class, including Ela. In the final project, nn students will participate in a choreography described below.

nn students are positioned on the positive side of the OxOx-axis. The ii-th dancer is located at ai>0a_i \gt 0. Some dancers will change positions during the dance (we'll call them movable dancers), and others will stay in the same place during a choreography (we'll call them immovable dancers). We distinguish the dancers using a binary string ss of length nn: if sis_i equals '1', then the ii-th dancer is movable, otherwise the ii-th dancer is immovable.

Let's call the "positive energy value" of the choreography d>0d \gt 0. The dancers will perform "movements" based on this value.

Each minute after the dance begins, the movable dancer with the smallest xx-coordinate will start moving to the right and initiate a "movement". At the beginning of the movement, the dancer's energy level will be initiated equally to the positive energy value of the choreography, which is dd. Each time they move from some yy to y+1y+1, the energy level will be decreased by 11. At some point, the dancer might meet other fellow dancers in the same coordinates. If it happens, then the energy level of the dancer will be increased by 11. A dancer will stop moving to the right when his energy level reaches 00, and he doesn't share a position with another dancer.

The dancers are very well-trained, and each "movement" will end before the next minute begins.

To show her understanding of this choreography, Ela has to answer qq queries, each consisting of two integers kk and mm. The answer to this query is the coordinate of the mm-th dancer of both types from the left at kk-th minute after the choreography begins. In other words, denote xk,1,xk,2,…,xk,nx_{k, 1}, x_{k, 2}, \dots, x_{k, n} as the sorted coordinates of the dancers at kk-th minute from the beginning, you need to print xk,mx_{k, m}.

DTL 工程师们热爱周末聚会,Ela 也不例外!但遗憾的是,她还不会跳舞。因此,她决定报名参加一个舞蹈班。

该舞蹈班共有 nn 名学生,其中包括 Ela。在期末项目中,这 nn 名学生将共同完成一段如下所述的编舞。

nn 名学生被安置在 OxOx 轴的正半轴上。第 ii 位舞者位于坐标 ai>0a_i \gt 0 处。在舞蹈过程中,部分舞者会改变位置(我们称其为可移动舞者),其余舞者则在整个编舞过程中保持原位不动(我们称其为不可移动舞者)。我们使用一个长度为 nn 的二进制字符串 ss 来区分这些舞者:若 si=’1’s_i = \text{'1'},则第 ii 位舞者是可移动的;否则,第 ii 位舞者是不可移动的。

我们称该编舞的“正能量值”为 d>0d \gt 0。所有舞者将依据该值执行“移动”。

自舞蹈开始后的每一分钟,当前 xx 坐标最小的可移动舞者将向右启动一次“移动”。在本次移动开始时,该舞者的能量值被初始化为编舞的正能量值 dd。每当他从位置 yy 移动到 y+1y+1 时,其能量值减少 11。在移动过程中,他可能与其他舞者处于同一坐标位置;若发生这种情况,则其能量值增加 11。当某位舞者的能量值降至 00,且此时他未与任何其他舞者共处同一位置时,他即停止向右移动。

舞者们训练有素,每次“移动”均会在下一分钟开始前结束。

为了展示自己对这段编舞的理解,Ela 需要回答 qq 个查询,每个查询包含两个整数 kk 和 mm。该查询的答案为:在编舞开始后第 kk 分钟时,所有 nn 位舞者(包括可移动与不可移动两类)按坐标从左到右排序后的第 mm 个坐标值。换言之,记第 kk 分钟时各舞者的坐标按升序排列为 xk,1,xk,2,…,xk,nx_{k, 1}, x_{k, 2}, \dots, x_{k, n},你需要输出 xk,mx_{k, m}。

输入格式

The first line contains three integers nn, dd and qq (1≤n≤1051 \le n \le 10^5; 1≤d≤1091 \le d \le 10^9; 1≤q≤1051 \le q \le 10^5) — the number of dancers, the positive energy value of the choreography, and the number of queries.

The second line contains nn integers a1,a2,…,ana_1, a_2, \dots, a_n (1≤a1<a2<⋯<an≤1091 \le a_1 \lt a_2 \lt \dots \lt a_n \le 10^9) — the coordinates of each dancer.

The third line contains a binary string ss of length nn — the movability of each dancer. Each character is either '0' or '1'. It is guaranteed that ss contains at least one character '1'.

Then qq lines follow, the ii-th of them contains two integers kik_i and mim_i (1≤ki≤1091 \le k_i \le 10^9, 1≤mi≤n1 \le m_i \le n) — the content of each query.

第一行包含三个整数 nn、dd 和 qq(1≤n≤1051 \le n \le 10^5;1≤d≤1091 \le d \le 10^9;1≤q≤1051 \le q \le 10^5)—— 分别表示舞者人数、编舞的正向能量值以及查询次数。

第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \dots, a_n(1≤a1<a2<⋯<an≤1091 \le a_1 \lt a_2 \lt \dots \lt a_n \le 10^9)—— 表示每位舞者的坐标。

第三行包含一个长度为 nn 的二进制字符串 ss —— 表示每位舞者的可移动性。每个字符为 '0' 或 '1'。保证 ss 中至少包含一个字符 '1'。

接下来是 qq 行,其中第 ii 行包含两个整数 kik_i 和 mim_i(1≤ki≤1091 \le k_i \le 10^9,1≤mi≤n1 \le m_i \le n)—— 表示每次查询的内容。

输出格式

Output qq lines, each contains a single integer — the answer for the corresponding query.

输出 qq 行,每行包含一个整数——对应查询的答案。

输入输出样例

  • 输入#1

    4 3 8
    1 3 6 7
    1011
    1 1
    1 2
    1 3
    1 4
    2 1
    2 2
    2 3
    2 4

    输出#1

    3
    5
    6
    7
    3
    6
    7
    10
  • 输入#2

    1 1 5
    2
    1
    1 1
    2 1
    3 1
    4 1
    5 1

    输出#2

    3
    4
    5
    6
    7

说明/提示

Let's consider the first example test case.

In the first minute, 11 is the lowest coordinate between movable dancers. The energy level is initiated with 33. Then the following happens:

  • The dancer moves from 11 to 22. The energy level decreased to 22.
  • The dancer moves from 22 to 33. The energy level decreased to 11, then increased to 22 when she met another dancer at 33.
  • The dancer moves from 33 to 44. The energy level decreased to 11.
  • The dancer moves from 44 to 55. The energy level decreased to 00.

At the end of the first minute, the sorted coordinates of the dancers become [3,5,6,7][3, 5, 6, 7], and their respective movability is '0111'.

In the second minute, 55 is the lowest coordinate between movable dancers. The energy level is initiated with 33. Then the following happens:

  • The dancer moves from 55 to 66. The energy level decreased to 22, then increased to 33 when she met another dancer at 66.
  • The dancer moves from 66 to 77. The energy level decreased to 22, then increased to 33 when she met another dancer at 77.
  • The dancer moves from 77 to 88. The energy level decreased to 22.
  • The dancer moves from 88 to 99. The energy level decreased to 11.
  • The dancer moves from 99 to 1010. The energy level decreased to 00.

At the end of the second minute, the sorted coordinates of the dancers become [3,6,7,10][3, 6, 7, 10], and their respective movability is '0111'.

我们来考虑第一个样例测试用例。

在第一分钟内,11 是所有可移动舞者中坐标最小的一个。此时能量值初始化为 33。随后发生如下过程:

  • 舞者从 11 移动到 22,能量值减少至 22。
  • 舞者从 22 移动到 33,能量值减少至 11;当她在 33 处遇到另一位舞者时,能量值增加至 22。
  • 舞者从 33 移动到 44,能量值减少至 11。
  • 舞者从 44 移动到 55,能量值减少至 00。

第一分钟结束时,舞者按坐标升序排列为 [3,5,6,7][3, 5, 6, 7],其对应的可移动性字符串为 '0111'。

在第二分钟内,55 是所有可移动舞者中坐标最小的一个。此时能量值初始化为 33。随后发生如下过程:

  • 舞者从 55 移动到 66,能量值减少至 22;当她在 66 处遇到另一位舞者时,能量值增加至 33。
  • 舞者从 66 移动到 77,能量值减少至 22;当她在 77 处遇到另一位舞者时,能量值增加至 33。
  • 舞者从 77 移动到 88,能量值减少至 22。
  • 舞者从 88 移动到 99,能量值减少至 11。
  • 舞者从 99 移动到 1010,能量值减少至 00。

第二分钟结束时,舞者按坐标升序排列为 [3,6,7,10][3, 6, 7, 10],其对应的可移动性字符串为 '0111'。

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

首页