BZOJ2086: [Poi2010]blocks

Source: Internet
Author: User

Exercises

Thought to find out just ask for the longest average >k.

The problem of the mean is to subtract k from each number and determine whether a continuous >0 is possible.

Then we find that if I<j and S[i]<s[j], then J is no better than I for l>j.

Then we can maintain a monotonous s[i], and then for each L go two to distinguish its answer.

But that would be t.

Consider monotonicity again.

If l>j, and S[l]>s[i], then our answer is the smallest and l-i, so J must take the smaller than I can update the answer. Then you can sweep the two hands over it.

All right, I admit that I'm a hu ...

Code:

1#include <cstdio>2#include <cstdlib>3#include <cmath>4#include <cstring>5#include <algorithm>6#include <iostream>7#include <vector>8#include <map>9#include <Set>Ten#include <queue> One#include <string> A #defineINF 1000000000 - #defineMAXN 1000000+5 - #defineMAXM 1000000+5 the #defineEPS 1e-10 - #definell Long Long - #definePA pair<int,int> - #defineFor0 (i,n) for (int i=0;i<= (n); i++) + #defineFor1 (i,n) for (int i=1;i<= (n); i++) - #defineFor2 (i,x,y) for (int i= (x); i<= (y); i++) + #defineFor3 (i,x,y) for (int i= (x); i>= (y); i--) A #defineFor4 (i,x) for (int i=head[x],y=e[i].go;i;i=e[i].next,y=e[i].go) at #defineMoD 1000000007 - using namespacestd; - inline ll read () - { -ll x=0, f=1;CharCh=GetChar (); -      while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; ch=GetChar ();} in      while(ch>='0'&&ch<='9') {x=Ten*x+ch-'0'; ch=GetChar ();} -     returnx*F; to } + intN,M,Q[MAXN]; - ll A[MAXN],B[MAXN]; the intMain () * { $Freopen ("Input.txt","R", stdin);Panax NotoginsengFreopen ("output.txt","W", stdout); -N=read (); m=read (); theFor1 (i,n) a[i]=read (); +      while(m--) A     { thell X=read ();intR=0; +Q[r=1]=b[0]=0; - For1 (i,n) $         { $b[i]=b[i-1]+a[i]-x; -           if(B[i]<b[q[r]]) q[++r]=i; -         } the         intans=0; -          for(intI=n;i>0&&r;i--)Wuyi         { the              while(R&&b[i]>=b[q[r]]) r--; -r++; Wu             if(B[i]>=b[q[r]]) Ans=max (ans,i-q[r]); -         } Aboutprintf"%d", ans);if(m) printf (" ");Elseprintf"\ n"); $     } -     return 0; -}
View Code 2086: [poi2010]blocks time limit:20 Sec Memory limit:259 MB
submit:199 solved:91
[Submit] [Status] Description

Given N positive integers A[1..N], and then given a positive integer k, you can now do the following: Each time you select a positive integer greater than K a[i], a[i] minus 1, select a[i-1] or a[i+1] one plus 1. After a certain number of operations, ask the maximum can be selected a continuous sub-sequence, so that each number of this sub-sequence is not less than K.
Give a total of M inquiry, each asked the K different, you need to answer separately.

Input

The first line is two positive integers n (n <= 1,000,000) and M (M <= 50).
The second row n positive integers, and the first positive integers represent a[i] (A[i] <= 10^9).
The third row of M positive integers, and the first positive integers denote the K (k <= 10^9) of the I inquiry.

Output

A total of one row, output m positive integer, number I indicates the answer to the first question.

Sample Input5 6
1 2 1) 1 5
1 2 3 4 5 6




Sample Output5 5 2 1 1 0

BZOJ2086: [Poi2010]blocks

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.