Bzoj 1342: [Baltic2007]sound mute problem [monotone queue]

Source: Internet
Author: User

1342: [Baltic2007]sound Mute issue time limit:5 Sec Memory limit:162 MB
submit:835 solved:372
[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 Naked Questionno need to flip the sequence
#include <iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>using namespacestd;Const intn=1e6+5; typedefLong LongLl;inlineintRead () {CharC=getchar ();intx=0, f=1;  while(c<'0'|| C>'9'){if(c=='-') f=-1; c=GetChar ();}  while(c>='0'&&c<='9') {x=x*Ten+c-'0'; c=GetChar ();} returnx*F;}intN,m,c,a[n],flag;intq1[n],h1,t1,q2[n],h2,t2;intMain () {//freopen ("In.txt", "R", stdin);N=read (); M=read (); c=read (); H1=h2=1; t1=t2=0;  for(intI=1; i<=n;i++) {A[i]=read ();  while(h1<=t1&&i-q1[h1]+1&GT;M) h1++;  while(h2<=t2&&i-q2[h2]+1&GT;M) h2++;  while(H1<=t1&&a[q1[t1]]<=a[i]) t1--; q1[++t1]=i;  while(H2<=t2&&a[q2[t2]]>=a[i]) t2--; q2[++t2]=i; if(i-m+1>=1&AMP;&AMP;A[Q1[H1]]-A[Q2[H2]]&LT;=C) printf ("%d\n", i-m+1), flag=1; }    if(!flag) puts ("NONE");}

Bzoj 1342: [Baltic2007]sound mute problem [monotone queue]

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.