#P15687. [ICPC 2023 Jakarta R] Maximize The Value

    ID: 15595 远端评测题 1000ms 1024MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>线段树2023扫描线差分ICPC离线处理

[ICPC 2023 Jakarta R] Maximize The Value

题目描述

You are given a one-based array consisting of N N integers: A1,A2,,AN A_1, A_2, \cdots, A_N . Initially, the value of each element is set to 0 0 .

There are M M operations (numbered from 1 1 to M M ). Operation i i is represented by Li,Ri,Xi \langle L_i, R_i, X_i \rangle . If operation i i is executed, all elements Aj A_j for LijRi L_i \leq j \leq R_i will be increased by Xi X_i .

You have to answer Q Q independent queries. Each query is represented by K,S,T \langle K, S, T \rangle which represents the following task. Choose a range [l,r] [l, r] satisfying SlrT S \leq l \leq r \leq T , and execute operations l,l+1,,r l, l + 1, \dots, r . The answer to the query is the maximum value of AK A_K after the operations are executed among all possible choices of l l and r r .

输入格式

The first line consists of two integers N N M M ( 1N,M100000 1 \leq N, M \leq 100\,000 ).

Each of the next M M lines consists of three integers Li L_i Ri R_i Xi X_i ( $ 1 \leq L_i \leq R_i \leq N; -100\,000 \leq X_i \leq 100\,000 $ ).

The following line consists of an integer Q Q ( 1Q100000 1 \leq Q \leq 100\,000 ).

Each of the next Q Q lines consists of three integers K K S S T T ( 1KN;1STM 1 \leq K \leq N; 1 \leq S \leq T \leq M ).

输出格式

For each query, output in a single line, an integer which represent the answer of the query.

2 6
1 1 -50
1 2 -20
2 2 -30
1 1 60
1 2 40
2 2 10
5
1 1 6
2 1 6
1 1 3
2 1 3
1 1 2
100
50
0
0
-20
5 3
1 3 3
2 4 -2
3 5 3
6
1 1 3
2 1 3
3 1 3
3 2 3
2 2 3
2 2 2
3
3
4
3
0
-2

提示

Explanation for the sample input/output #1

For query 1 1 , one of the solutions is to execute operation 4 4 and 5 5 .

For query 2 2 , one of the solutions is to execute operation 4 4 , 5 5 , and 6 6 .

For query 3 3 , the only solution is to execute operation 3 3 .

For query 4 4 , the only solution is to execute operation 1 1 .

For query 6 6 , the only solution is to execute operation 2 2 .