CF877F Ann and Books
Description
In Ann's favorite book shop are as many as $ n $ books on math and economics. Books are numbered from $ 1 $ to $ n $ . Each of them contains non-negative number of problems.
Today there is a sale: any subsegment of a segment from $ l $ to $ r $ can be bought at a fixed price.
Ann decided that she wants to buy such non-empty subsegment that the sale operates on it and the number of math problems is greater than the number of economics problems exactly by $ k $ . Note that $ k $ may be positive, negative or zero.
Unfortunately, Ann is not sure on which segment the sale operates, but she has $ q $ assumptions. For each of them she wants to know the number of options to buy a subsegment satisfying the condition (because the time she spends on choosing depends on that).
Currently Ann is too busy solving other problems, she asks you for help. For each her assumption determine the number of subsegments of the given segment such that the number of math problems is greaten than the number of economics problems on that subsegment exactly by $ k $ .
Input Format
N/A
Output Format
N/A
Explanation/Hint
In the first sample Ann can buy subsegments $ [1;1],[2;2],[3;3],[2;4] $ if they fall into the sales segment, because the number of math problems is greater by $ 1 $ on them that the number of economics problems. So we should count for each assumption the number of these subsegments that are subsegments of the given segment.
Segments $ [1;1] $ and $ [2;2] $ are subsegments of $ [1;2] $ .
Segments $ [1;1],[2;2] $ and $ [3;3] $ are subsegments of $ [1;3] $ .
Segments $ [1;1],[2;2],[3;3],[2;4] $ are subsegments of $ [1;4] $ .
Segment $ [3;3] $ is subsegment of $ [3;4] $ .