1342: [Baltic2007]Sound静音问题
Time Limit: 5 Sec Memory Limit: 162 MBSubmit: 710 Solved: 307
[Submit][Status][Discuss]
Description
静音问题 数字录音中,声音是用表示空气压力的数字序列描述的,序列中的每个值称为一个采样,每个采样之间间隔一定的时间。 很多声音处理任务都需要将录到的声音分成由静音隔开的几段非静音段。为了避免分成过多或者过少的非静音段,静音通常是这样定义的:m个采样的序列,该序列中采样的最大值和最小值之差不超过一个特定的阈值c。 请你写一个程序,检测n个采样中的静音。
Input
第一行有三个整数n,m,c( 1<= n<=1000000,1<=m<=10000, 0<=c<=10000),分别表示总的采样数、静音的长度和静音中允许的最大噪音程度。第2行n个整数ai (0 <= ai <= 1,000,000),表示声音的每个采样值,每两个整数之间用空格隔开。
Output
列出了所有静音的起始位置i(i满足max(a[i, . . . , i+m−1]) − min(a[i, . . . , i+m−1]) <= c),每行表示一段静音的起始位置,按照出现的先后顺序输出。如果没有静音则输出NONE。
Sample Input
7 2 0
0 1 1 2 3 2 2
0 1 1 2 3 2 2
Sample Output
2
6
6
HINT
Source
题解:直接单调队列水水哒。。。
1 var 2 a3,a4,a1,a2,i,j,k,l,m,n,c:longint; 3 a,d1,d2:array[0..1000005] of longint; 4 flag:boolean; 5 pr:array[0..10] of longint; 6 function check(x:longint):boolean;inline; 7 begin 8 exit(((a[d1[a3]]-a[d2[a4]])<=c) and (x>=m)); 9 end; 10 begin 11 readln(n,m,c); 12 for i:=1 to n do read(a[i]); 13 readln; 14 flag:=false; 15 d1[1]:=1;d2[1]:=1;a3:=1;a1:=1;a4:=1;a2:=1; 16 if check(1) then 17 begin 18 writeln(1); 19 flag:=true; 20 end; 21 for i:=2 to n do 22 begin 23 while (d1[a3]+m)<=i do inc(a3); 24 while (a3<=a1) and (a[d1[a1]]<=a[i]) do dec(a1); 25 inc(a1);d1[a1]:=i; 26 while (d2[a4]+m)<=i do inc(a4); 27 while (a4<=a2) and (a[d2[a2]]>=a[i]) do dec(a2); 28 inc(a2);d2[a2]:=i; 29 if check(i) then 30 begin 31 writeln(i-m+1); 32 flag:=true; 33 end; 34 end; 35 if not(flag) then writeln('NONE'); 36 readln; 37 end.