#P7719. 「EZEC-10」多彩的线段

    ID: 8247 远端评测题 1500ms 512MiB 尝试: 0 已通过: 0 难度: 9 上传者: 标签>树形数据结构2021洛谷原创O2优化

「EZEC-10」多彩的线段

Problem Description

Muxii has a number line [1,n][1,n] and line segments in mm different colors.
Muxii specifies that for the ii-th color, only the interval [li,ri][l_i,r_i] on the number line is allowed to be covered by segments of this color, and the length of each segment must not exceed kik_i (ki10)(k_i\le 10). There can be any number of segments.
Now Muxii will ask you qq queries. Each query gives two numbers aa and bb. Please answer: to cover the interval [a,b][a,b] on the number line, what is the minimum number of segments needed.
It is guaranteed that there is no position on the number line that cannot be covered by any segment.

Input Format

Some testdata in this problem enforces online queries.
The first line contains four integers oo, nn, mm, qq. When o=1o=1, this testdata enforces online queries, i.e., the real aa and bb are obtained by XOR-ing the given aa and bb with the answer to the previous query. For the first query, you may assume the previous answer is 00. When o=0o=0, this testdata does not enforce online queries.
The next mm lines each contain three integers lil_i, rir_i, kik_i.
The next qq lines each contain two integers aa, bb. The meanings of all variables not explained here have already been given in the description.

Output Format

Output qq lines, each containing one integer representing the answer.

0 7 2 1
1 5 3
4 7 2
1 7
3

Hint

[Sample 11 Explanation]

At least 33 segments are needed. One feasible solution is:
The 11st segment is [1,4][1,4], color 11;
The 22nd segment is [4,6][4,6], color 22;
The 33rd segment is [6,7][6,7], color 22.

[Constraints and Notes]

  • Subtask 1 (5 points): n,m,q1000n,m,q\le 1000, no online requirement.
  • Subtask 2 (20 points): n2×105n\le 2\times 10^5. No online requirement.
  • Subtask 3 (20 points): n107n\le 10^7. No online requirement.
  • Subtask 4 (10 points): m1000m\le 1000. No online requirement.
  • Subtask 5 (25 points): no special limits, no online requirement.
  • Subtask 6 (20 points): no special limits, online required.

For 100%100\% of the data, it is guaranteed that 1n1091\le n\le 10^9, 1m2×1051\le m\le 2\times 10^5, 1q1061\le q\le 10^6, 1li<rin1\le l_i<r_i\le n, 1kimin(10,rili)1\le k_i\le \min(10,r_i-l_i), 1a<bn1\le a<b\le n. All variables above are integers.

Translated by ChatGPT 5