CF1614E.Divan and a Cottage
普及/提高-
通过率:0%
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 P in the morning, and the street temperature is T , then by the next morning the temperature in the house changes according to the following rule:
- Pnew=P+1 , if P<T ,
- Pnew=P−1 , if P>T ,
- Pnew=P , if P=T .
Here Pnew 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 n days. In the beginning of the i -th day, the temperature outside Ti is first given to you. After that, on the i -th day, you will receive ki queries. Each query asks the following: "if the temperature in the house was xi at the morning of the first day, what would be the temperature in the house next morning (after day i )?"
Please answer all the businessman's queries.
输入格式
The first line of the input contains the number n ( 1≤n≤2⋅105 ) — the number of days.
The following is a description of n days in the following format.
The first line of the description contains an integer Ti ( 0≤Ti≤109 ) — the temperature on that day.
The second line contains a non-negative integer ki ( 0≤ki≤2⋅105 ) — the number of queries that day.
The third line contains k integers xi′ ( 0≤xi′≤109 ) — the encrypted version of Divan's queries.
Let lastans=0 initially. Divan's actual queries are given by xi=(xi′+lastans)mod(109+1) , where amodb is the reminder when a is divided by b . After answering the query, set lastans to the answer.
It is guaranteed that the total number of queries (the sum of all ki ) does not exceed 2⋅105 .
输出格式
For each query, output a single integer — the temperature in the house after day i .
输入输出样例
输入#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 50 on the first day, 50 on the second day, and 0 on the third day.
Note that lastans=0 initially.
- The initial temperature of the first query of the first day is (1+lastans)mod(109+1)=1 . After the first day, the temperature rises by 1 , because 1<50 . So the answer to the query is 2 . Then, we set lastans=2 .
- The initial temperature of the second query of the first day is (2+lastans)mod(109+1)=4 . After the first day, the temperature rises by 1 , because 4<50 . So the answer to the query is 5 . Then, we set lastans=5 .
- The initial temperature of the third query of the first day is (3+lastans)mod(109+1)=8 . After the first day, the temperature rises by 1 . So the answer to the query is 9 . Then, we set lastans=9 .
- The initial temperature of the first query of the second day is (4+lastans)mod(109+1)=13 . After the first day, the temperature rises by 1 . After the second day, the temperature rises by 1 . So the answer to the query is 15 . Then, we set lastans=15 .