CF1906F.Maximize The Value

提高+/省选-

通过率:0%

时间限制:1.00s

内存限制:1024MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given a one-based array consisting of NN integers: A1,A2,⋯ ,ANA_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 ⟨Li,Ri,Xi⟩\langle L_i, R_i, X_i \rangle. If operation ii is executed, all elements AjA_j for Li≤j≤RiL_i \leq j \leq R_i will be increased by XiX_i.

You have to answer QQ 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 S≤l≤r≤TS \leq l \leq r \leq T, and execute operations l,l+1,…,rl, l + 1, \dots, r. The answer to the query is the maximum value of AKA_K after the operations are executed among all possible choices of ll and rr.

给你一个基于 1 的数组,包含 NN 个整数:A1,A2,⋯ ,ANA_1, A_2, \cdots, A_N。初始时,每个元素的值均为 00。

共有 MM 个操作(编号从 11 到 MM)。第 ii 个操作表示为 ⟨Li,Ri,Xi⟩\langle L_i, R_i, X_i \rangle。若执行第 ii 个操作,则对所有满足 Li≤j≤RiL_i \leq j \leq R_i 的元素 AjA_j 均增加 XiX_i。

你需要回答 QQ 个相互独立的查询。每个查询表示为 ⟨K,S,T⟩\langle K, S, T \rangle,其含义如下:选择一个区间 [l,r][l, r],满足 S≤l≤r≤TS \leq l \leq r \leq T,并执行操作 l,l+1,…,rl, l + 1, \dots, r。该查询的答案是在所有可能的 ll 和 rr 的选择中,执行完这些操作后 AKA_K 所能达到的最大值。

输入格式

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

Each of the next MM lines consists of three integers LiL_i RiR_i XiX_i (1≤Li≤Ri≤N;−100 000≤Xi≤100 0001 \leq L_i \leq R_i \leq N; -100\,000 \leq X_i \leq 100\,000).

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

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

第一行包含两个整数 NN 和 MM(1≤N,M≤100 0001 \leq N, M \leq 100\,000)。

接下来的 MM 行,每行包含三个整数 LiL_i、RiR_i 和 XiX_i(1≤Li≤Ri≤N1 \leq L_i \leq R_i \leq N;−100 000≤Xi≤100 000-100\,000 \leq X_i \leq 100\,000)。

随后一行包含一个整数 QQ(1≤Q≤100 0001 \leq Q \leq 100\,000)。

接下来的 QQ 行,每行包含三个整数 KK、SS 和 TT(1≤K≤N1 \leq K \leq N;1≤S≤T≤M1 \leq S \leq T \leq M)。

输出格式

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

对于每个查询,在一行中输出一个整数,表示该查询的答案。

输入输出样例

  • 输入#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

    输出#1

    100
    50
    0
    0
    -20
  • 输入#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

    输出#2

    3
    3
    4
    3
    0
    -2

说明/提示

Explanation for the sample input/output #1

For query 11, one of the solutions is to execute operation 44 and 55.

For query 22, one of the solutions is to execute operation 44, 55, and 66.

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

For query 44, the only solution is to execute operation 11.

For query 66, the only solution is to execute operation 22.

样例输入/输出 #1 的说明

对于查询 11,一种可行的方案是执行操作 44 和 55。

对于查询 22,一种可行的方案是执行操作 44、55 和 66。

对于查询 33,唯一的方案是执行操作 33。

对于查询 44,唯一的方案是执行操作 11。

对于查询 66,唯一的方案是执行操作 22。

输入解题思路,AI测评打分。不知道怎么写?

首页