I have a sequence! Time Limit: 20000/10000ms (java/others) Memory Limit: 128000/64000kb (java/others) SubmitStatusProblem Description
Little Sunny Day: "I have a series!" ”
Small sunny Day: "I also have a lot of series!" ”
So a small sunny day to the sequence of all successive sub-series of the write out.
Then a sunny day writes the largest number in each successive sub-series.
So, how many are bigger than k?
Input
Multiple sets of data, first a positive integer t (t<=100), representing the number of groups of data
For each set of data, the first is two integers n (1<=n<=200000), K (0<=k<=10^9), but the sum of n in all data does not exceed 1000000.
Next is n integers a[i] (1<=a[i]<=10^9)
Output for each set of data, outputs an integer that represents the number of consecutive sub-sequences with the largest element greater than K. Sample Input
23 21 2 3 3 1 1 2 3
Sample Output
35
Hint
For sample one, there are 6 consecutive subsequence {1}{2}{3}{1,2}{2,3}{1,2,3} (note {1,3} does not meet test instructions because it is discontinuous)
A total of 3 {3}{2,3}{1,2,3} with the largest element greater than 2
For example two, there are 5 consecutive sub-sequences greater than 1, {2}{3}{1,2}{2,3}{1,2,3}
1#include <iostream>2#include <stdio.h>3#include <stdlib.h>4#include <math.h>5#include <string.h>6 using namespacestd;7typedefLong Longll;8ll t,n,k,a[200005],d[200005],cou;9 /**Ten after scanning from the go, for the value of a[i]>k, the number of sequences satisfying the condition =i+1. One for the value of a[i]<=k, it will be equal to d[i-1]. The sequence range is at least the distance from I to the previous maximum value. The number of sequences will be the maximum number of values. A Of course, this will be all the scope of the past, there will be no leakage, the value of all added up. - */ - intMain () the { -scanf"%lld",&t); - while(t--) - { +scanf"%lld%lld",&n,&k); -cou=0; +memset (D,0,sizeof(d)); A for(intI=0; i<n;i++) at { -scanf"%lld",&a[i]); - if(a[i]>k) - { -d[i]+=i+1; - } in Else - { to if(i>0) d[i]=d[i-1]; + Elsed[i]=0; - } thecou+=D[i]; * } $printf"%d\n", cou);Panax Notoginseng } - return 0; the}View Code
I have a sequence!