Codeforces round #262 (Div. 2) C (Binary answer, latency tag)

Source: Internet
Author: User

This is a type of question that maximizes the minimum value. This type of question is typically answered using a bipartite enumeration.

In the case of a binary answer, first determine the exact range of the answer. Then, the key is how to judge the answer line for each enumeration.

I use the [I] array to indicate the height of the flowers in the initial phase. B [I] indicates how much the flowers will increase to reach the answer of the current enumeration (that is, the value of the MID. The two arrays are very computation. The key is the continuous pouring of W flowers. How to update the interval (violent O (n2) Will time out after the update )? You can use a line segment tree, but this question does not involve a range query.Update intervals on an array, Using the line segment tree. In fact, this update can be solved by O (n) with the concept of delay mark (lazy operation. For more information, see hdu4970.

Lazy [] the function of marking the array is to record where the update interval is stopped.

# Include <iostream> # include <cstdio> # include <cstdlib> # include <cstring> # include <cmath> # include <map> # include <set> # include <vector> # include <algorithm> # include <stack> # include <queue> using namespace STD; # define INF 1000000000 # define EPS 1e-8 # define PII pair <int, int> # define ll long intconst int maxn = 110009; int n, m, W, a [maxn], B [maxn], lazy [maxn], ANS = 0;/* lazy [] the function of marking the array is actually to record where to stop the update range */INT main () {// freopen ("in6.txt", "r", stdin); scanf ("% d", & N, & M, & W ); for (INT I = 1; I <= N; I ++) {scanf ("% d", & A [I]) ;} int L = 1, R = maxn + INF, mid; while (L <= r) {memset (lazy, 0, sizeof (lazy); Mid = (R + l)/2; for (INT I = 1; I <= N; I ++) B [I] = max (0, mid-A [I]); int TM = m, X = 0; For (INT I = 1; I <= N; I ++) // start watering {x + = lazy [I]; // check whether this step is marked with B [I]-= x; // Add the watering operation that affects the current B [I] To if (B [I]> 0) // It must be greater than 0, then you have to start watering it again {TM-= B [I]; If (tm <0) break; // The number of days is limited to lazy [I + W]-= B [I]; x + = B [I] ;}} if (tm <0) r = mid-1; else {ans = mid; L = Mid + 1 ;}} printf ("% d \ n", ANS );}

 

Codeforces round #262 (Div. 2) C (Binary answer, latency tag)

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.