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

Source: Internet
Author: User

At first, I wrote a rmq and then t ...

Well, the positive solution is a monotone queue that maintains two monotone queues ...

--------------------------------------------------------------------------------

#include <bits/stdc++.h>#define REP (i, n) for (int i = 0; i < n; i++)#define CLR (x, C) memset (x, C, sizeof (x))using namespace std;const int MAXN = 1000009; int SEQ[MAXN], n, M, C;deque<int> mn, MX;vector<int> ans;int main () {freopen ("test.in", "R", stdin);freopen ("Test.out", "w", stdout);cin >> n >> m >> C;Rep (i, N) scanf ("%d", seq + i);ans.clear ();for (int i = n-1; ~i; i--) {if (!mn.empty () && Mn.front ()-I >= m) Mn.pop_front ();if (!mx.empty () && Mx.front ()-I >= m) Mx.pop_front ();while (!mn.empty () && seq[mn.back ()] >= seq[i]) mn.pop_back ();while (!mx.empty () && seq[mx.back ()] <= seq[i]) mx.pop_back ();Mn.push_back (i);Mx.push_back (i);if (i <= n-m && seq[mx.front ()]-Seq[mn.front ()] <= c)Ans.push_back (i + 1);}if (ans.size ())for (int i = Ans.size ()-1; ~i; i--) printf ("%d\n", Ans[i]);Elseputs ("NONE");return 0;}

--------------------------------------------------------------------------------

1342: [Baltic2007]sound mute problem time limit: 5 Sec Memory Limit: 162 MB
Submit: 725 Solved: 312
[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

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.