408784: GYM103316 K Cuvira's Mecha Co-Pilot

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

Description

K. Cuvira's Mecha Co-Pilot time limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output

You are an elite metalbending soldier personally selected by Cuvira to aid her in piloting the "secret weapon" that will crush the enemies of the Earth Empire. Although you are a proficient bender, Cuvira would like to do the honors of moving the mech herself, and has instead delegated you to quickly calculating the necessary adjustments to keep the mech running smoothly.

The state of the contraption can be represented as a single array of $$$N$$$ integers, which is initially filled with zeroes. Cuvira will periodically shout out commands to update the array based on her planned movements and requests for information about the array after the updates that have occurred thus far. A command to update the array will consist of two integers $$$1 \leq x \leq y \leq N$$$, and you will add $$$(a-x+1)(a-x+2)$$$ to the $$$a$$$-th element of the array for every $$$a$$$ between $$$x$$$ and $$$y$$$, inclusive. A request for information about the array will also consist of two integers $$$1 \leq x \leq y \leq N$$$, but you will instead reply with the sum of array elements indexed from $$$x$$$ to $$$y$$$, inclusive, modulo $$$10^9+7$$$.

As Cuvira diverted her entire investment into the main artillery built into the mech, she neglected to provide an onboard computer/HUD for you to keep track of the computations. Lucky for you, there is a programmable calculator in your pocket that you can use to efficiently respond to Cuvira's queries.

Input

The first line contains two integers $$$N$$$ and $$$Q$$$ ($$$1 \leq N, Q \leq 10^5$$$) that represent the length of the mech array and the number of commands/requests Cuvira shouts out to you, respectively. The next $$$Q$$$ lines each contain three space separated integers $$$t$$$, $$$x$$$, and $$$y$$$ ($$$1 \leq t \leq 2$$$ and $$$1 \leq x \leq y \leq N$$$). For a command as described above, $$$t = 1$$$, and otherwise $$$t = 2$$$ to denote a request. The meaning of integers $$$x$$$ and $$$y$$$ in each case are described above.

Output

Print out a single integer for each request Cuvira makes on its own line, and in the order in which they are given to you.

ExampleInput
8 4
1 1 8
2 7 8
1 4 6
2 5 6
Output
128
90

加入题单

上一题 下一题 算法标签: