zoukankan      html  css  js  c++  java
  • BZOJ 1342: [Baltic2007]Sound静音问题( 单调队列 )

    一开始写了个RMQ然后就T了...

    好吧正解是单调队列, 维护两个单调队列... 

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

    #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 ", ans[i]);
    else
       puts("NONE");
    return 0;
    }

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

    1342: [Baltic2007]Sound静音问题

    Time Limit: 5 Sec  Memory Limit: 162 MB
    Submit: 725  Solved: 312
    [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

    Sample Output

    2
    6

    HINT

    Source

  • 相关阅读:
    1094. Car Pooling
    121. Best Time to Buy and Sell Stock
    58. Length of Last Word
    510. Inorder Successor in BST II
    198. House Robber
    57. Insert Interval
    15. 3Sum java solutions
    79. Word Search java solutions
    80. Remove Duplicates from Sorted Array II java solutions
    34. Search for a Range java solutions
  • 原文地址:https://www.cnblogs.com/JSZX11556/p/4669106.html
Copyright © 2011-2022 走看看