Maximize The Value

시간 제한2초메모리 제한1024 MB

요약
각 질의 (K,S,T)마다 [S,T] 안에서 연속한 연산 구간 l..r을 골라 위치 K에 더해지는 값의 최댓값을 구한다.
난이도

보통10점 중 7점

유형
누적 합, 동적 계획법, 세그먼트 트리, 배열
정답자
아직 제출이 없습니다

문제

You are given a one-based array consisting of NN integers: A_1,A_2,⋯ ,A_NA\_1, A\_2, \cdots , A\_N. Initially, the value of each element is set to 00.

There are MM operations (numbered from 11 to MM). Operation ii is represented by ⟨L_i,R_i,X_i⟩⟨L\_i , R\_i , X\_i⟩. If operation ii is executed, all elements A_jA\_j for L_i≤j≤R_iL\_i ≤ j ≤ R\_i will be increased by X_iX\_i.

You have to answer QQ independent queries. Each query is represented by ⟨K,S,T⟩⟨K, S, T⟩ which represents the following task. Choose a range \[l,r]\[l, r] satisfying S≤l≤r≤TS ≤ l ≤ r ≤ T, and execute operations l,l+1,…,rl, l + 1, \dots , r. The answer to the query is the maximum value of A_KA\_K after the operations are executed among all possible choices of ll and rr.

입력

The first line consists of two integers NN MM (1≤N,M≤100,0001 ≤ N, M ≤ 100\\, 000).

Each of the next MM lines consists of three integers L_iL\_i R_iR\_i X_iX\_i (1≤L_i≤R_i≤N1 ≤ L\_i ≤ R\_i ≤ N; −100,000≤X_i≤100,000-100\\, 000 ≤ X\_i ≤ 100\\, 000).

The following line consists of an integer QQ (1≤Q≤100,0001 ≤ Q ≤ 100\\, 000).

Each of the next QQ lines consists of three integers KK SS TT (1≤K≤N1 ≤ K ≤ N; 1≤S≤T≤M1 ≤ S ≤ T ≤ M).

출력

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

예제2

  1. 예제 1

    입력
    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
    
  2. 예제 2

    입력
    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