Codeforces Round 259 (Div. 1)
E
Little Pony and Lord Tirek
Codeforces
3100
原题
← D→
翻译中…

Lord Tirek is a centaur and the main antagonist in the season four finale episodes in the series "My Little Pony: Friendship Is Magic". In "Twilight's Kingdom" (Part 1), Tirek escapes from Tartarus and drains magic from ponies to grow stronger.

翻译中…

image

翻译中…

The core skill of Tirek is called Absorb Mana. It takes all mana from a magic creature and gives them to the caster.

翻译中…

Now to simplify the problem, assume you have $*n*$ ponies (numbered from 1 to $*n*$). Each pony has three attributes:

翻译中…
  • $*s*_{*i*}$ : amount of mana that the pony has at time 0;
  • $*m*_{*i*}$ : maximum mana that the pony can have;
  • $*r*_{*i*}$ : mana regeneration per unit time.
翻译中…

Lord Tirek will do $*m*$ instructions, each of them can be described with three integers: $*t*_{*i*}, *l*_{*i*}, *r*_{*i*}$. The instruction means that at time $*t*_{*i*}$, Tirek will use Absorb Mana on ponies with numbers from $*l*_{*i*}$ to $*r*_{*i*}$ (both borders inclusive). We'll give you all the $*m*$ instructions in order, count how much mana Tirek absorbs for each instruction.

翻译中…

Input

翻译中…

The first line contains an integer $*n*$ ($1 ≤ *n* ≤ 10^{5}$) — the number of ponies. Each of the next $*n*$ lines contains three integers $*s*_{*i*}, *m*_{*i*}, *r*_{*i*}$ $(0 ≤ *s*_{*i*} ≤ *m*_{*i*} ≤ 10^{5}; 0 ≤ *r*_{*i*} ≤ 10^{5})$, describing a pony.

翻译中…

The next line contains an integer $*m*$ ($1 ≤ *m* ≤ 10^{5}$) — the number of instructions. Each of the next $*m*$ lines contains three integers $*t*_{*i*}, *l*_{*i*}, *r*_{*i*}$ $(0 ≤ *t*_{*i*} ≤ 10^{9}; 1 ≤ *l*_{*i*} ≤ *r*_{*i*} ≤ *n*)$, describing an instruction of Lord Tirek. The instructions are given in strictly increasing order of $*t*_{*i*}$ (all $*t*_{*i*}$ are distinct).

翻译中…

Output

翻译中…

For each instruction, output a single line which contains a single integer, the total mana absorbed in this instruction.

翻译中…

Note

翻译中…

Every pony starts with zero mana. For the first instruction, each pony has 5 mana, so you get 25 mana in total and each pony has 0 mana after the first instruction.

翻译中…

For the second instruction, pony 3 has 14 mana and other ponies have mana equal to their $*m*_{*i*}$.

翻译中…

样例

Input #1
5
0 10 1
0 12 1
0 20 1
0 12 1
0 10 1
2
5 1 5
19 1 5
Output #1
25
58
InputCopy OutputCopy
题目信息
题号
453E
时间限制
3 s
内存限制
256 MB
标签
数据结构

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。