Watt
InterviewTime limit2sMemory limit1024 MB
Given an array, handle range-assign updates and count the contiguous subarrays with an even sum inside a query interval.
- Level
Medium6 of 10
- Topics
- Segment tree, Prefix sum, Math
- Solved
- No attempts yet
Problem
Watt burst into the room. He had it. He had finally worked out the math behind it, and now he could show it to everyone. He had been right all along.
- STEAM ENGINE! shouted Watt.
Everyone stared in disbelief.
- What does your 'steam engine' actually do, Watt? asked Marin skeptically.
- You give it an array of numbers and perform operations on it. One type of operation sets every element of an interval to a value. The other gives it an interval, and it tells you how many contiguous subarrays inside that interval have an even sum. Steam engine!
Marin covered his eyes with his hand.
- Fine, let's try it.
Input
The first line contains natural numbers and (), the length of the array given to the steam engine and the number of operations.
The next line contains the initial array of natural numbers ().
Each of the next lines is one operation, in the order they are performed. Each line has one of the following two forms:
- : Set every element from position to position () to the value ().
- : Ask the steam engine how many contiguous subarrays of the interval from position to position () have an even sum.
At least one operation has the second form.
Output
For each operation of the second form, print the steam engine's answer on its own line.
Hint
The interval contains 6 distinct contiguous subarrays, and 2 of them have an even sum: and . The second answer is 0 because the fourth element is 5, which is odd. The third answer equals the first because the query was the same.