407962: GYM102951 D Static Range Queries

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

D. Static Range Queriestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output

There is an array $$$a$$$ of length $$$10^9$$$, initially containing all zeroes.

First perform $$$N$$$ updates of the following form:

  • Given integers $$$l$$$, $$$r$$$, and $$$v$$$, add $$$v$$$ to all values $$$a_l, a_{l+1}, \dots, a_{r-1}$$$.

Then, answer $$$Q$$$ queries of the following form:

  • Given integers $$$l$$$ and $$$r$$$, print the sum $$$a_l + a_{l+1} + \dots + a_{r-1}$$$.
Input

Line 1: The two space-separated integers $$$N$$$ and $$$Q$$$ ($$$1 \leq N,Q \leq 10^5$$$)

Lines 2..N+1: Each line contains three space-separated integers $$$l$$$, $$$r$$$, and $$$v$$$, corresponding to an update ($$$0 \leq l < r \leq 10^9$$$, $$$v \leq 10^4$$$).

Lines N+2..N+Q+1: Each line contains two space-separated integers $$$l$$$ and $$$r$$$, corresponding to a query ($$$0 \leq l < r \leq 10^9$$$).

Output

Print $$$Q$$$ lines, the answers to the queries in the same order as given in the input.

ExamplesInput
5 5
3 7 2
1 10 4
1 6 10
0 4 10
6 7 1
5 7
0 2
5 9
1 6
4 9
Output
23
34
31
106
47
Input
5 5
8 9 3
1 6 2
2 5 9
4 8 6
2 7 4
5 8
2 7
5 7
5 10
2 7
Output
28
73
22
31
73
Input
5 5
2 9 5
2 10 1
2 9 9
2 5 10
6 8 8
7 10
0 4
2 6
0 1
0 7
Output
39
50
90
0
113

加入题单

上一题 下一题 算法标签: