Problem Description
n person have just entered a company, and Xiaoxun, as a supervisor, gives each of them a number from 1 to n that is not repeated.
In order to let them to get to know each other better, they would have a party every day, and there was a limit on the number of people at each party. Xiaoxun didn't want to find a way to find people randomly. So every time he had a party, he would only invite people with numbers in a certain interval to play.
The people who come to the party will get to know each other, and Xiaoxun wants to know how effective each party is. The effect is evaluated as the number of pairs of people at this party who did not appear at the same previous party.
Input
There are mutiple test cases.
Each case starts with a line containing two integers n,m(n≤5×105,m≤5×105) which represent the number of people and the number of parties. And this is followed by m lines each containing two integers l,r(1≤l≤r≤n) which mean the interval, and only the people whose number in the interval can take part in this party.
Output
For each case you should print m lines.
Each line containing a integer mean the effect of this party.
Sample Input
5 4 1 2 4 5 1 4 2 5
Sample Output
1 1 5 2
Hint
explaination of sample: The first party: 1-2 The second party: 4-5 The third party: 1-3 1-4 2-3 2-4 3-4 The fourth party: 2-5 3-5
这个题当时不会做啊,还是看的题解才想明白的。
就是先看一个区间,然后每个值让他的a[i]=i,每次要查询时,需要先更新一下这个区间内所有的a[i]。
a[i]更改的目标值是这个区间内最左端点的a[i]值。
用原始a[i]减去现在a[i]并累加就是和了。
但是要注意区间最大值的维护。
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include