#P9494. 「SFCOI-3」进行一个走的行

    ID: 10576 远端评测题 3500ms 512MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>倍增平衡树2023洛谷原创O2优化差分

「SFCOI-3」进行一个走的行

Background

Announcement: Note that cases with li>ril_i > r_i may occur; in such cases, the operation is invalid.


Xiao L is keen on walking.

Problem Description

Xiao L arrives at a tourist attraction and wants to walk along the main road there.

There are several key points on the main road. He can model them as a sequence aa of length nn. Each aia_i is a triple (li,ri,vi)(l_i, r_i, v_i), meaning:

  • If ri=1r_i = -1, it represents a scenic spot that requires buying a ticket to enter. The ticket costs lil_i coins, and after the visit he will gain viv_i happiness.
  • If ri1r_i \neq -1, it represents a gift distribution point. If the total face value of the coins he holds is xx and satisfies lixril_i \leq x \leq r_i, he can claim one gift and will gain viv_i happiness.

He plans to walk along this main road mm times. Each time, he is given the starting point ll and the ending point rr. At the beginning, the total face value of the coins he holds is xx, and his initial happiness is 00.

He will start from ll and pass through i[l,r]i \in [l, r] from left to right. He will do the following:

  • If ri=1r_i = -1, if he still has coins left after paying the current ticket fee, he will visit this scenic spot.
  • If ri1r_i \neq -1, if possible, he will claim one gift.

Please help him quickly compute his happiness after each walk ends.

Input Format

The first line contains two integers n,mn, m.

The next nn lines: the ii-th line contains three integers li,ri,vil_i, r_i, v_i.

The next mm lines: each line contains three integers l,r,xl, r, x, describing one query.

Output Format

Output mm lines, each containing one integer, representing the happiness after the walk ends.

4 10
1 1 4
5 -1 4
1 9 19
8 -1 10
1 1 11
2 2 4
3 3 5
4 4 14
1 2 1
2 3 9
3 4 1
1 3 9
2 4 8
1 4 10
0
0
19
10
4
23
19
23
23
23

Hint

This problem uses bundled testdata.

  • Subtask 1 (10 pts): 1n,m5×1031 \leq n, m \leq 5 \times 10^3.
  • Subtask 2 (10 pts): ri1r_i \neq -1.
  • Subtask 3 (20 pts): ri=1r_i = -1.
  • Subtask 4 (10 pts): 1n,m7.5×1041 \leq n, m \leq 7.5 \times 10^4, Property A.
  • Subtask 5 (20 pts): 1n,m7.5×1041 \leq n, m \leq 7.5 \times 10^4.
  • Subtask 6 (10 pts): The testdata is generated randomly within the constraints, Property B.
  • Subtask 7 (20 pts): No special restrictions.

Property A: 1li7.5×1041 \leq l_i \leq 7.5 \times 10^4, ri=1r_i = -1 or 1ri7.5×1041 \leq r_i \leq 7.5 \times 10^4, 1x7.5×1041 \leq x \leq 7.5 \times 10^4.

Property B: When ri=1r_i = -1, 1li2×1051 \leq l_i \leq 2 \times 10^5.

For 100%100\% of the testdata:

  • 1n,m2×1051 \leq n, m \leq 2 \times 10^5.
  • 1li1091 \leq l_i \leq 10^9, ri=1r_i = -1 or 1ri1091 \leq r_i \leq 10^9.
  • 1vi1091 \leq v_i \leq 10^9.
  • 1lrn1 \leq l \leq r \leq n, 1x1091 \leq x \leq 10^9.

Translated by ChatGPT 5