#P8797. [蓝桥杯 2022 国 A] 三角序列

    ID: 9713 远端评测题 3000ms 512MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>莫队2022可持久化线段树分块蓝桥杯国赛

[蓝桥杯 2022 国 A] 三角序列

Background

Thanks to Lotuses for providing the testdata.

Problem Description

Given nn pairs of numbers ai,bia_i, b_i, each pair represents a triangle with aia_i rows and aia_i columns as shown in the figure:

When bi=0b_i = 0, the left side is lower; when bi=1b_i = 1, the right side is lower.

Concatenate the triangles corresponding to each pair from left to right in the given order.

Now there are mm queries li,ri,vil_i, r_i, v_i. For each query, find the minimum height hih_i such that, between columns lil_i and rir_i, the number of oo whose height is within hih_i is at least viv_i.

Input Format

The first line contains two integers n,mn, m, separated by a space.

The next nn lines each contain two integers ai,bia_i, b_i, separated by a space.

The next mm lines each contain three integers li,ri,vil_i, r_i, v_i, where adjacent integers are separated by a space.

Output Format

Output one line containing a string representing the answer.

6 6
3 0
4 0
2 1
3 1
5 0
1 1
3 9 12
3 9 13
3 4 4
14 16 7
9 15 12
1 18 42
2
3
3
3
3
-1

Hint

Sample Explanation

The range corresponding to the first query is shown in the figure:

Constraints

  • For 30%30\% of the test cases, 1n,m,ai5001 \leq n, m, a_i \leq 500.
  • For 50%50\% of the test cases, 1n,m,ai50001 \leq n, m, a_i \leq 5000.
  • For all test cases, 1n,m2×1051 \leq n, m \leq 2\times10^5, 1ai1061 \leq a_i \leq 10^6, 0bi10 \leq b_i \leq 1, 1liriai1 \leq l_i \leq r_i \leq \sum a_i, 1vi10181 \leq v_i \leq 10^{18}.

Lanqiao Cup 2022 National Contest A Group, Problem I.

Translated by ChatGPT 5