"BZOJ1342" "Baltic2007" sound mute problem monotone queue

Source: Internet
Author: User

#include <stdio.h>int main () {puts ("reprint please specify source thank you");p UTS ("http://blog.csdn.net/vmurder/article/details/42971677 ");}


Test instructions

Although this problem is Chinese, I need to say a little bit about test instructions.

is to ask you the length of the interval of M, the maximum value of the interval-the minimum value <=c, the output of the left end of the interval.

Attention!!! If no scenario output is none.

Exercises

First we can write a multiset2400ms+, that is, and then seemingly can also write a line tree (do not know if anyone wrote)


But the positive solution is obviously to write a monotone queue of two O (n).

One maintains the current interval maximum and the other maintains the minimum value.

Code:

#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #define N 1001000# Define INF 0x3f3f3f3fusing namespace Std;int id1[n],x1[n],l1,r1;int id2[n],x2[n],l2,r2;int n,m,p,s[n];int main () { Freopen ("Test.in", "R", stdin), int i;scanf ("%d%d%d", &n,&m,&p), for (i=1;i<=n;i++) scanf ("%d", &s[i ]); L1=l2=1,r1=r2=0;int flag=1;for (i=1;i<=n;i++) {while (l1<=r1&&i-id1[l1]>=m) L1++;while (l2<= r2&&i-id2[l2]>=m) L2++;while (L1<=r1&&s[i]>=x1[r1]) r1--;while (L2<=r2&&s[i] <=X2[R2]) r2--;id1[++r1]=id2[++r2]=i;x1[r1]=x2[r2]=s[i];if (i>=m) if (x1[l1]-x2[l2]<=p) printf ("%d\n", i-m+ 1), flag=0;} if (flag) puts ("NONE"); return 0;}


"BZOJ1342" "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.