CF1614E.Divan and a Cottage

省选/NOI-

通过率:0%

时间限制:2.00s

内存限制:1024MB

AC君温馨提醒

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

题目描述

Divan's new cottage is finally complete! However, after a thorough inspection, it turned out that the workers had installed the insulation incorrectly, and now the temperature in the house directly depends on the temperature outside. More precisely, if the temperature in the house is PP in the morning, and the street temperature is TT, then by the next morning the temperature in the house changes according to the following rule:

  • Pnew=P+1P_{new} = P + 1, if P<TP \lt T,
  • Pnew=P−1P_{new} = P - 1, if P>TP \gt T,
  • Pnew=PP_{new} = P, if P=TP = T.

Here PnewP_{new} is the temperature in the house next morning.

Divan is a very busy businessman, so sometimes he is not at home for long periods and does not know what the temperature is there now, so he hired you to find it. You will work for nn days. In the beginning of the ii-th day, the temperature outside TiT_i is first given to you. After that, on the ii-th day, you will receive kik_i queries. Each query asks the following: "if the temperature in the house was xix_i at the morning of the first day, what would be the temperature in the house next morning (after day ii)?"

Please answer all the businessman's queries.

迪万的新别墅终于完工了!然而,经过全面检查后发现,工人们错误地安装了隔热层,导致屋内的温度直接受到室外温度的影响。更准确地说,如果某天早晨屋内温度为 PP,而室外温度为 TT,那么到第二天早晨,屋内温度将按如下规则变化:

  • 若 P<TP \lt T,则 Pnew=P+1P_{\text{new}} = P + 1;
  • 若 P>TP \gt T,则 Pnew=P−1P_{\text{new}} = P - 1;
  • 若 P=TP = T,则 Pnew=PP_{\text{new}} = P。

其中 PnewP_{\text{new}} 表示第二天早晨的屋内温度。

迪万是一位非常忙碌的商人,因此有时会长时间不在家,无法得知当前屋内温度,于是他聘请你来计算该温度。你将工作 nn 天。在第 ii 天开始时,首先会给你当天的室外温度 TiT_i;随后,在第 ii 天内,你将收到 kik_i 个查询。每个查询的形式为:“若第一天早晨屋内温度为 xix_i,那么经过第 ii 天后(即第 i+1i+1 天早晨),屋内温度将是多少?”

请回答这位商人的所有查询。

输入格式

The first line of the input contains the number nn (1≤n≤2⋅1051 \leq n \leq 2 \cdot 10^5) — the number of days.

The following is a description of nn days in the following format.

The first line of the description contains an integer TiT_i (0≤Ti≤1090 \leq T_i \leq 10^9) — the temperature on that day.

The second line contains a non-negative integer kik_i (0≤ki≤2⋅1050 \le k_i \le 2 \cdot 10^5) — the number of queries that day.

The third line contains kk integers xi′x'_i (0≤xi′≤1090 \leq x'_{i} \leq 10^9) — the encrypted version of Divan's queries.

Let lastans=0lastans = 0 initially. Divan's actual queries are given by xi=(xi′+lastans) mod (109+1)x_i = (x'_i + lastans) \bmod (10^9 + 1), where a mod ba \bmod b is the reminder when aa is divided by bb. After answering the query, set lastanslastans to the answer.

It is guaranteed that the total number of queries (the sum of all kik_i) does not exceed 2⋅1052 \cdot 10^5.

输入的第一行包含一个整数 nn(1≤n≤2⋅1051 \leq n \leq 2 \cdot 10^5),表示天数。

接下来是对 nn 天的描述,格式如下:

每一天的描述包含三行:

  • 第一行包含一个整数 TiT_i(0≤Ti≤1090 \leq T_i \leq 10^9),表示当天的温度;
  • 第二行包含一个非负整数 kik_i(0≤ki≤2⋅1050 \le k_i \le 2 \cdot 10^5),表示当天的查询次数;
  • 第三行包含 kik_i 个整数 xi′x'_i(0≤xi′≤1090 \leq x'_{i} \leq 10^9),表示 Divan 查询的加密版本。

令初始时 lastans=0lastans = 0。Divan 的实际查询为 xi=(xi′+lastans) mod (109+1)x_i = (x'_i + lastans) \bmod (10^9 + 1),其中 a mod ba \bmod b 表示 aa 除以 bb 所得的余数。每次回答完一个查询后,需将 lastanslastans 更新为该次查询的答案。

保证查询总数(即所有 kik_i 之和)不超过 2⋅1052 \cdot 10^5。

输出格式

For each query, output a single integer — the temperature in the house after day ii.

对于每个查询,输出一个整数——第 ii 天后屋内的温度。

输入输出样例

  • 输入#1

    3
    50
    3
    1 2 3
    50
    3
    4 5 6
    0
    3
    7 8 9

    输出#1

    2
    5
    9
    15
    22
    30
    38
    47
    53
  • 输入#2

    4
    728
    3
    859 1045 182
    104
    1
    689
    346
    6
    634 356 912 214 1 1
    755
    3
    241 765 473

    输出#2

    858
    1902
    2083
    2770
    3401
    3754
    4663
    4874
    4872
    4870
    5107
    5868
    6337
  • 输入#3

    2
    500000000
    3
    1000000000 999999999 888888888
    250000000
    5
    777777777 666666666 555555555 444444444 333333333

    输出#3

    999999999
    999999996
    888888882
    666666656
    333333321
    888888874
    333333317
    666666648

说明/提示

Let's look at the first four queries from the example input.

The temperature is 5050 on the first day, 5050 on the second day, and 00 on the third day.

Note that lastans=0lastans = 0 initially.

  • The initial temperature of the first query of the first day is (1 + lastans) mod (109+1)=1(1 \, + \, lastans) \bmod (10^9 + 1) = 1. After the first day, the temperature rises by 11, because 1<501 \lt 50. So the answer to the query is 22. Then, we set lastans=2lastans = 2.
  • The initial temperature of the second query of the first day is (2 + lastans) mod (109+1)=4(2 \, + \, lastans) \bmod (10^9 + 1) = 4. After the first day, the temperature rises by 11, because 4<504 \lt 50. So the answer to the query is 55. Then, we set lastans=5lastans = 5.
  • The initial temperature of the third query of the first day is (3 + lastans) mod (109+1)=8(3 \, + \, lastans) \bmod (10^9 + 1) = 8. After the first day, the temperature rises by 11. So the answer to the query is 99. Then, we set lastans=9lastans = 9.
  • The initial temperature of the first query of the second day is (4 + lastans) mod (109+1)=13(4 \, + \, lastans) \bmod (10^9 + 1) = 13. After the first day, the temperature rises by 11. After the second day, the temperature rises by 11. So the answer to the query is 1515. Then, we set lastans=15lastans = 15.

我们来看示例输入中的前四个查询。

第一天的温度为 5050,第二天的温度为 5050,第三天的温度为 00。

注意:初始时 lastans=0lastans = 0。

  • 第一天的第一个查询的初始温度为 (1 + lastans) mod (109+1)=1(1 \, + \, lastans) \bmod (10^9 + 1) = 1。经过第一天后,温度上升 11,因为 1<501 \lt 50。因此该查询的答案为 22。然后,我们将 lastanslastans 更新为 22。
  • 第一天的第二个查询的初始温度为 (2 + lastans) mod (109+1)=4(2 \, + \, lastans) \bmod (10^9 + 1) = 4。经过第一天后,温度上升 11,因为 4<504 \lt 50。因此该查询的答案为 55。然后,我们将 lastanslastans 更新为 55。
  • 第一天的第三个查询的初始温度为 (3 + lastans) mod (109+1)=8(3 \, + \, lastans) \bmod (10^9 + 1) = 8。经过第一天后,温度上升 11。因此该查询的答案为 99。然后,我们将 lastanslastans 更新为 99。
  • 第二天的第一个查询的初始温度为 (4 + lastans) mod (109+1)=13(4 \, + \, lastans) \bmod (10^9 + 1) = 13。经过第一天后,温度上升 11;再经过第二天后,温度又上升 11。因此该查询的答案为 1515。然后,我们将 lastanslastans 更新为 1515。

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

首页