1342: [Baltic2007]sound Mute issue time limit:5 Sec Memory limit:162 MB
submit:710 solved:307
[Submit] [Status] [Discuss] Description Mute problem in digital recording, the sound is described by a sequence of numbers that represent air pressure, each of which is called a sample, and the interval between each sample is a certain amount of time. Many sound processing tasks require that the recorded sound be divided into a few non-silent segments separated by silence. To avoid dividing into too many or too few non-silent segments, muting is usually defined as: M-sampled sequences, where the difference between the maximum and minimum values sampled in the sequence does not exceed a specific threshold of C. Please write a program to detect the Silence in N samples. The first line of input has three integers n,m,c (1<= n<=1000000,1<=m<=10000, 0<=c<=10000), respectively, representing the total number of samples, the length of the mute, and the maximum allowable noise level in silence. The 2nd row n integer ai (0 <= ai <= 1,000,000) represents each sampled value of the sound, separated by a space between every two integers. Output lists all mute start positions I (I meet Max (A[i, ..., i+m−1]) −min (a[i, ..., i+m−1]) <= c), each line represents the starting position of a mute, in the order in which it appears. If there is no mute, the output is none. Sample Input7 2 0
0 1 1 2 3 2 2
Sample Output2
6
HINT Source
The direct monotone queue water water da ...
1 var2 A3,a4,a1,a2,i,j,k,l,m,n,c:longint;3A,D1,D2:Array[0..1000005] ofLongint;4 Flag:boolean;5prArray[0..Ten] ofLongint;6 functionCheck (x:longint): Boolean;inline;7 begin8Exit (((A[D1[A3]]-A[D2[A4)) <=c) and(x>=m));9 End;Ten begin One readln (n,m,c); A fori:=1 toN Doread (a[i]); - Readln; -flag:=false; thed1[1]:=1;d 2[1]:=1; a3:=1; a1:=1; a4:=1; a2:=1; - ifCheck1) Then - begin -Writeln (1); +flag:=true; - End; + fori:=2 toN Do A begin at while(d1[a3]+m) <=i DoInc (A3); - while(A3<=A1) and(A[d1[a1]]<=a[i]) DoDec (a1); -Inc (A1);d 1[a1]:=i; - while(d2[a4]+m) <=i DoInc (A4); - while(A4<=A2) and(A[d2[a2]]>=a[i]) DoDec (a2); -Inc (A2);d 2[a2]:=i; in ifCheck (i) Then - begin toWriteln (i-m+1); +flag:=true; - End; the End; * if not(flag) ThenWriteln ('NONE'); $ Readln;Panax Notoginseng End.
1342: [Baltic2007]sound mute problem