Problem Description
There are n men ,every man has an ID(1..n).their ID is unique. Whose ID is i and i-1 are friends, Whose ID is i and i+1 are friends. These n men stand in line. Now we select an interval of men to make some group. K men in a group can create K*K value. The value of an interval is sum of these value of groups. The people of same group's id must be continuous. Now we chose an interval of men and want to know there should be how many groups so the value of interval is max.
Input
First line is T indicate the case number. For each case first line is n, m(1<=n ,m<=100000) indicate there are n men and m query. Then a line have n number indicate the ID of men from left to right. Next m line each line has two number L,R(1<=L<=R<=n),mean we want to know the answer of [L,R].
Output
For every query output a number indicate there should be how many group so that the sum of value is max.
Sample Input
Sample Output
题目大概:
连续的数字的个数的平方是给数列的价值,在价值最大的情况下,最长的序列是多少。
思路:
用树状数组,离线一下数据,按照右区间排序,注意的是维护到了第i要看一下前面有没有和它连续的。
这个题是借鉴自其他人的代码思路。
引----
解题思路:用树状数组离线维护,把询问按照右区间递增排序,然后从1~n维护,维护到i时注意找寻前i个是不是有a[i]-1,和a[i]+1,有的话直接去掉,因为
这两个数必定要和a[i]分到一组,留一个就好了。
代码: