HDU 2795 billboard (calculates the maximum value for the single-point update interval of a line segment tree)

Source: Internet
Author: User

Question connection: http://acm.hdu.edu.cn/showproblem.php? PID = 1, 2795

Q: There is an H * w advertisement version, and there are n 1 * W [I] advertisements. The principle of putting advertisements on the top is as much as possible and putting them on the left is as far as possible, ask the number of rows where the advertisement can be put down. If the advertisement cannot be put down, print-1;


Idea: we can build a line based on each row. Each leaf represents the capacity of each row, and the node stores the maximum value of the sub-node, and then quickly finds a row that can store and put down the advertisement.

In short, it is still a simple line segment tree problem. The difficulty lies in the abstract model.


# Include <iostream> # include <cstdio> # define mid (L + r)> 1 # define ls RT <1 # define Rs RT <1 | 1 # define lson L, M, RT <1 # define rson m + 1, R, RT <1 | 1 # define Max 999999 using namespace STD; int IMAX [max <2]; inline void pushup (int rt) {IMAX [RT] = max (IMAX [ls], IMAX [RS]);} void build (int w, int L, int R, int RT) {If (L = r) {IMAX [RT] = W; return;} int M = mid; build (W, lson); Build (W, rson); pushup (RT);} int query (int x, int L, int R, int RT) {If (L = r) {IMAX [RT]-= X; return L;} int M = mid; int ret = (IMAX [ls]> = x )? Query (x, lson): Query (x, rson); pushup (RT); return ret;} int main () {int H, W, N; while (~ Scanf ("% d", & H, & W, & N) {// optimized: If the space is far better than h> N, then let H = N (one row and one advertisement) if (h> N) H = N; build (W, 1, h, 1); While (n --) {int X; scanf ("% d", & X); If (IMAX [1] <X) // if no position is found at the top of puts ("-1 "); else printf ("% d \ n", query (x, 1, h, 1) ;}} return 0 ;}


HDU 2795 billboard (calculates the maximum value for the single-point update interval of a line segment tree)

Related Article

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.