pre[i]第i位數往前走多少位碰到和它相同的數
dp[i]表示長度為i的子串,dp[i]可以由dp[i-1]加上從i到n的pre[i]>i-1的數減去最後一段長度為i-1的斷中的不同的數得到....
爆int+有點卡內存....
Substrings
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2300 Accepted Submission(s): 716
Problem Description XXX has an array of length n. XXX wants to know that, for a given w, what is the sum of the distinct elements’ number in all substrings of length w. For example, the array is { 1 1 2 3 4 4 5 } When w = 3, there are five substrings of length 3. They are (1,1,2),(1,2,3),(2,3,4),(3,4,4),(4,4,5)
The distinct elements’ number of those five substrings are 2,3,3,2,2.
So the sum of the distinct elements’ number should be 2+3+3+2+2 = 12
Input There are several test cases.
Each test case starts with a positive integer n, the array length. The next line consists of n integers a
1,a
2…a
n, representing the elements of the array.
Then there is a line with an integer Q, the number of queries. At last Q lines follow, each contains one integer w, the substring length of query. The input data ends with n = 0 For all cases, 0
6, 0<=Q<=104, 0<= a1,a2…an <=106
Output For each test case, your program should output exactly Q lines, the sum of the distinct number in all substrings of length w for each query.
Sample Input
7
1 1 2 3 4 4 5
3
1
2
3
0
Sample Output
7
10
12
Source 2012 Asia Hangzhou Regional Contest
/* ***********************************************
Author :CKboss
Created Time :2015年08月17日 星期一 22時06分06秒
File Name :HDOJ4455.cpp
************************************************ */
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include