#P15796. 【MX-J28-T3】「Cfz Round 8」Juice Problem

    ID: 17698 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 显示难度普及 上传者: 标签>数学O2优化前缀和梦熊比赛

【MX-J28-T3】「Cfz Round 8」Juice Problem

Problem Description

There are n+1n+1 cups in front of Yuki, numbered from 00 to nn. For cups 11 to nn, both the capacity and the current amount of juice are fixed: cup ii has capacity aia_i and currently contains bib_i units of juice. Cup 00 has capacity 10910^9, and the amount of juice in it is not fixed.

Yuki defines operation ii as pouring the juice in cup i−1i-1 into cup ii. If at this time the amount of juice in cup ii exceeds its capacity, the juice will overflow until the amount of juice in the cup becomes equal to its capacity.

Now Yuki has qq queries. The ii-th query gives two parameters vi,piv_i, p_i. You need to find: if cup 00 contains viv_i units of juice, then after Yuki performs operations 1,2,…,pi1,2,\dots,p_i in order, how much juice will be in cup pip_i.

Note that these operations are not actually performed, meaning the queries are independent of each other.

Input Format

This problem contains multiple test cases.

The first line contains two non-negative integers c,tc,t, representing the test point ID and the number of test cases. c=0c=0 means this test point is the sample.

Then each test case is given as follows:

  • The first line contains two non-negative integers n,qn,q.
  • The next nn lines: the ii-th line contains two non-negative integers ai,bia_i,b_i.
  • The next qq lines: the ii-th line contains two non-negative integers vi,piv_i,p_i.

Output Format

For each test case:

  • Output qq lines. The ii-th line contains one integer, the answer to the ii-th query.
0 1
3 3
4 0
9 8
13 8
5 1
0 2
3 3
4
8
13
0 2
5 3
3 1
6 2
9 3
7 2
8 0
4 3
0 4
1 5
2 1
0 0
3 1
5 2
8
7
7
1

Hint

Sample 1 Explanation

This sample contains 11 test case.

For the 11st query:

  • Cup 00 contains 55 units of juice. After pouring it into cup 11, since cup 11 has capacity 44 and 5>45 \gt 4, the juice overflows. Therefore, cup 11 finally contains 44 units of juice.

For the 22nd query:

  • After operation 11, cup 11 contains 00 units of juice.
  • After operation 22, cup 22 contains 88 units of juice.

For the 33rd query:

  • After operation 11, cup 11 contains 33 units of juice.
  • After operation 22, cup 22 contains 99 units of juice.
  • After operation 33, cup 33 contains 1313 units of juice.

Constraints

For all testdata:

  • 1≤t≤31 \le t \le 3.
  • 1≤n≤2×1051 \le n \le 2\times10^5, 0≤q≤2×1050 \le q \le 2\times10^5.
  • For all 1≤i≤n1 \le i \le n, 0≤bi≤ai≤1090 \le b_i \le a_i \le 10^9.
  • For all 1≤i≤q1 \le i \le q, 0≤vi≤1090 \le v_i \le 10^9, 1≤pi≤n1 \le p_i \le n.

::cute-table{tuack}

Test Point ID n,q≤n,q \le Special Property
1∼31\sim3 2×1032\times10^3 None
44 2×1052\times10^5 AC
5∼85\sim8 ^ A
99 BC
10∼1310\sim13 B
14,1514,15 C
16∼2016 \sim 20 None
  • Special Property A: for all 1≤i<n1 \le i \lt n, ai≥ai+1a_i \ge a_{i+1}.
  • Special Property B: for all 1≤i≤n1 \le i \le n, ai≤ai+1a_i \le a_{i+1}.
  • Special Property C: for all 1≤i≤n1 \le i \le n, bi=0b_i=0.

Translated by ChatGPT 5