hackercup / 2014 /finals /intervals_of_love.html
wjomlex's picture
2014 Problems
718fd53 verified
raw
history blame contribute delete
No virus
3.17 kB
<p>
Do you remember helping Prince Z.A.Y. rescue the princess of the kingdom of Hackadia from an evil dragon in Round 2? Well, as it so often happens, Z.A.Y. has fallen in love with his dearest princess. However, the princess has given Z.A.Y. a puzzle to solve to ensure that the one she marries is both brave and clever.
</p>
<p>
The princess gives Z.A.Y a 0-indexed array of <b>N</b> integers, and she asks him a series of questions. In each question, she provides an inclusive interval to the prince, and asks him how many subarrays in that interval are slowly increasing.
</p>
<p>
A subarray is defined as a contiguous set of integers in the given array.
A subarray is slowly increasing iff each integer in the subarray after the first is exactly 1 more than the previous integer. For example, <b>[1, 2, 3]</b>, <b>[5]</b>, and <b>[10, 11, 12]</b> are slowly increasing, but <b>[7, 9]</b>, <b>[13, 12, 11]</b>, and <b>[1, 1, 2, 2]</b> are not.
</p>
<p>
Easy problem, right? Yup, so the princess is going to make it more challenging since she knows the prince is seeking help from the best Hackers from the world. Sometimes, instead of asking a question, the princess will change an integer in the array.
</p>
<p>
Still an easy problem, right? Probably, but the princess isn't going to make it any harder (the prince *did* rescue her from a dragon, and could probably use a break).
</p>
<h3>Input</h3><p>
The first line consists of a single integer <b>T</b>, the number of test cases.
Each test case starts with a line containing an integer <b>N</b>, the length of the array.
Then 1 line follows with <b>N</b> integers <b>X<sub>i</sub></b> representing the elements of the array.
Then 1 line follows with an integer <b>M</b>, the number of actions the princess takes (questions and updates).
Then <b>M</b> lines follow, each with 3 integers.
The first integer, <b>op</b>, represents the action the princess takes.
If <b>op</b> is <b>0</b>, then 2 integers <b>P</b> and <b>K</b> follow, meaning that the princess will change the <b>P</b>th element of the array to <b>K</b>.
If <b>op</b> is <b>1</b>, then 2 integers <b>L</b> and <b>R</b> follow, meaning that the princess will ask how many slowly increasing subarrays there are between <b>L</b> and <b>R</b> (inclusive).
</p>
<h3>Output</h3>
<p>
For each test case <i>i</i>, output "Case #i: " followed by a single integer, the sum of the answers to the princess's questions. Since this number might be large, output it modulo 1,000,000,007.
</p>
<h3>Explanation of Sample</h3>
<p>
In the first sample case, the answer to the first question is 6 (the slowly increasing subarrays are [4], [5], [6], [4, 5], [5, 6], [4, 5, 6]), and the answer to the second question is 12. So the sum is 18.
</p>
<p>
In the second sample case, the answers are 3, 4, and 6 respectively, so the sum is 13.
</p>
<h3>Constraints</h3>
<p>
1 &le; <b>T</b> &le; 20 <br/>
1 &le; <b>N</b> &le; 10<sup>6</sup> <br/>
1 &le; <b>M</b> &le; 10<sup>6</sup> <br/>
1 &le; <b>X<sub>i</sub></b>, <b>K</b> &le; 10<sup>9</sup><br/>
0 &le; <b>P</b> &lt; <b>N</b> <br/>
0 &le; <b>op</b> &le; 1 <br/>
0 &le; <b>L</b> &le; <b>R</b> &lt; <b>N</b>
</p>