#P3168. [CQOI2015] 任务查询系统

    ID: 2217 远端评测题 2000ms 512MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>2015重庆线段树各省省选主席树可持久化

[CQOI2015] 任务查询系统

Description

The laboratory is building a task management system for its supercomputer, and you are assigned to implement the query component.

Each task in the supercomputer is described by a triple (si,ei,pi)(s_i, e_i, p_i), meaning it runs from second sis_i through second eie_i inclusive (the task is running at both second sis_i and second eie_i), and its priority is pip_i. Multiple tasks may run at the same time, and their priorities may be the same or different.

The scheduler frequently asks the query system: among the tasks running at second xix_i, what is the sum of priorities of the smallest kik_i tasks (i.e., sort tasks by priority in ascending order and take the first kik_i)?

In particular, if kik_i is larger than the number of tasks running at second xix_i, return the sum of priorities of all tasks running at second xix_i. All parameters are integers, and the time range is within [1,n][1, n].

Input Format

The first line contains two space-separated positive integers mm and nn, the number of tasks and the time range, respectively.

The next mm lines each contain three space-separated positive integers si,ei,pis_i, e_i, p_i (sieis_i \le e_i), describing one task.

The next nn lines each contain four space-separated integers xi,ai,bi,cix_i, a_i, b_i, c_i, describing one query.

This problem is online. The parameter kik_i is computed by ki=1+(ai×pre+bi)modcik_i = 1 + (a_i \times \text{pre} + b_i) \bmod c_i, where pre\text{pre} denotes the previous query’s result, with initial pre=1\text{pre} = 1.

Output Format

Output nn lines, each containing one integer, the result of each query.

4 3
1 2 6
2 3 3
1 3 2
3 3 4
3 1 3 2
1 1 3 4
2 2 4 3
2
8
11

Hint

[Sample explanation]

k1=(1×1+3)mod2+1=1k_1 = (1\times 1 + 3)\bmod 2 + 1 = 1.

k2=(1×2+3)mod4+1=2k_2 = (1\times 2+3)\bmod 4 + 1 = 2.

k3=(2×8+4)mod3+1=3k_3 = (2 \times 8+4)\bmod 3+1 = 3.

Constraints

For 100%100\% of the testdata, 1m,n,ci1051 \le m, n, c_i \le 10^5, 0ai,bi1050 \le a_i, b_i \le 10^5, 1siein1 \le s_i \le e_i \le n, 1pi1071 \le p_i \le 10^7, and the xix_i form a permutation of 11 to nn.

Note: On 2024-12-28 a hack testdata was added, post link.

Translated by ChatGPT 5