"BZOJ4385" [Poi2015]wilcze do?y "monotone queue" "prefix and" "" "and" "".

Source: Internet
Author: User

"Topic link"

Exercises

If the interval [j, I] is fixed, then it must be that the largest part of the weight becomes 0.

Using a monotone queue to maintain a sub-Piete with the maximal weights within a period (here the right endpoint subscript, set to X), enumerate right end I, use the ruler method to calculate J.

An interval [j, I] is valid for the condition of Sum[i]-sum[j-1]-(sum[x]-sum[x-d]) <= p.


Complexity of:

Time complexity: Because each point traverses up to 2 times, the complexity is O (n).

Space complexity: O (N)


RE:

I forgot to write H <= t when I updated J. If you write the right shot, you should be able to shoot it.


GET:

If d = 0, then it is the most bare ruler.

From the ruler method, think of the following methods, but can prove to be wrong:

1 First find the longest interval, meet the interval and not less than P, and then the maximum weight of the section into 0, and then expand.

counter example: n = 9,p = 3,d = 1,10 1 1 1 10 1 2 1 1, the answer should be 4.

2 Find the interval with the maximum weight of D, change to 0, and then expand from here.

counter example: n = 8,p = 19,d = 2,10 11 12 10 1 1 1 1, the answer should be 7.

So it is not possible to maintain the static, consider adding a number, and then think of the standard solution, but do not know how to maintain a fixed length of the interval of the maximum value of the sub-segment.

You should use the monotone queue + prefix and.

Again by the monotone queue + prefix and stuck, it seems to be summed up.

/* telekinetic Forest Guard */#include <cstdio> #include <cstring> #include <algorithm>using namespace Std;typedef Long Long ll;const int maxn = 2000005;int N, D; LL p, sum[maxn];int q[maxn];template <class numtype>inline void Read (Numtype &x) {bool F = 0; x = 0; char ch = g Etchar (); for (Ch < ' 0 ' | | ch > ' 9 '; ch = getchar ()) F = ch = = '-'? 1:0;for (; Ch >= ' 0 ' && ch <= ' 9 '; ch = getchar ()) x = x * + ch-' 0 '; if (f) x =-X;} int main () {read (n); Read (P); Read (d); for (int i = 1; I <= n; i++) read (Sum[i]), sum[i] + = sum[i-1];int h = 1, t = 0, ans = 0;for (int i = d, j = 1; I <= n; i++) {for (; h <= t && sum[i]-sum[i-d] > Sum[q[t]]-sum[q[t]- D];  t--) Q[++t] = I;for (; h <= t && sum[i]-sum[j-1]-(sum[q[h]]-sum[q[h]-d]) > P; j + +) if (Q[h]-D <= j) H++;ans = max (ans, i-j + 1);} printf ("%d\n", ans); return 0;}


"BZOJ4385" [Poi2015]wilcze do?y "monotone queue" "prefix and" "" "and" "".

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.