HDU 2795 Billboard. (line segment tree)

Source: Internet
Author: User

HDU 2795 Billboard. (line segment tree)

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


~~~~

Start to learn about the data structure. Let's start with a simple process. If you get tired of questions, write a problem-solving report. Haha, boiling, Segment tree!

~~~~

A h * w billboard, after which n 1 * wi-sized advertisements are pasted on the billboard in turn, and always pasted to the top left corner, q: What is the height after all advertisements are posted?

# Include
 
  
# Include # define lson rt <1, s, mid # define rson rt <1 | 1, mid + 1, eusing namespace std; const int maxn = 222222; int tre [maxn <2]; int h, w, n; void pushup (int rt) {tre [rt] = max (tre [rt <1], tre [rt <1 | 1]);} void build (int rt, int s, int e) {tre [rt] = w; if (s = e) return; int mid = (s + e)> 1; build (lson); build (rson);} int query (int rt, int s, int e, int x) {if (s = e) {tre [rt]-= x; return s;} int mid = (s + e)> 1; int ans = (tre [rt <1 ]> = X )? Query (lson, x): query (rson, x); pushup (rt); // write the update operation directly to the query function. Return ans;} int main () {while (scanf ("% d", & h, & w, & n) = 3) {if (h> n) h = n; // h> n, the extra space will be wasted, and RE build (, h) will appear ); while (n --) {int q; scanf ("% d", & q); if (tre [1]
  
   

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.