hdu 4455 Substrings(计数)】的更多相关文章

题目链接:hdu 4455 Substrings 题目大意:给出n,然后是n个数a[1] ~ a[n], 然后是q次询问,每次询问给出w, 将数列a[i]分成若干个连续且元素数量为w的集合,计算每个集合中出现的数字种类,输出总和. 解题思路:一开始想到遍历的算法,保持集合元素为w,每次剔除最前一个,加入一个,移动集合,维护数字种类,这种算法的复杂度为o(n^2), 但是超时了,后来看了下题解,dp[i] = dp[i - 1] + sum[i] - cnt; http://blog.csdn.n…
Substrings Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 3240    Accepted Submission(s): 990 Problem Description XXX has an array of length n. XXX wants to know that, for a given w, what is t…
Substrings Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1161    Accepted Submission(s): 351 Problem Description XXX has an array of length n. XXX wants to know that, for a given w, what is…
Substrings Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1727    Accepted Submission(s): 518 Problem Description XXX has an array of length n. XXX wants to know that, for a given w, what is…
Substrings Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 3269    Accepted Submission(s): 999 Problem Description XXX has an array of length n. XXX wants to know that, for a given w, what is t…
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 a…
题意: 给一串数字,给q个查询,每次查询长度为w的所有子串中不同的数字个数之和为多少. 解法:先预处理出D[i]为: 每个值的左边和它相等的值的位置和它的位置的距离,如果左边没有与他相同的,设为n+8(看做无穷). 考虑已知w=k的答案,推w = k+1时,这时每个区间都将增加一个数,即后n-k个数会增加到这些区间中,容易知道,如果区间内有该数,那么个数不会加1,,即D[i] > k时,结果++,即查询后n-k个数有多少个D[i] > k 的数即为要加上的数,然后最后面还会损失一个区间,损失的…
这个……真心看不出来是个DP,我在树状数组的康庄大道上欢快的奔跑了一下午……看了题解才发现错的有多离谱. 参考:http://www.cnblogs.com/kuangbin/archive/2012/11/11/2765329.html #include <cstdio> #include <cstring> #include <cstdlib> #include <algorithm> #define LL long long int using nam…
Different Circle Permutation Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 218    Accepted Submission(s): 106 Problem Description You may not know this but it's a fact that Xinghai Square is…
Birthday Toy Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 644    Accepted Submission(s): 326 Problem Description AekdyCoin loves toys. It is AekdyCoin’s Birthday today and he gets a special “…