Codeforces 35E (interval update)

Source: Internet
Author: User

Test instructions: To build n tall buildings, give the left and right intervals and heights of each tall building, and ask what points the outlines of all the buildings include.
The problem: This good pit, with n posture or has been WA, and then until the need to add input output file that sentence can be too ... The maximum value in the maintenance interval is the height of the segment tree, and the left and right intervals to 1e9 are discretized. Because the maintenance is the maximum value of each paragraph rather than the point, so divide the left and right sub-range to the mid to the mid+1 also belong to the sub-range.

#include <cstdio>#include <cstring>#include <algorithm>#include <map>using namespace STD;Const intN =100005;intN, A[n <<1], H[n], l[n], r[n], HH;intTree[n <<4], Res[n <<3][2]; map<int, int>mpvoidPushdown (intK) {if(Tree[k]) {Tree[k *2] = max (TREE[K *2], tree[k]); Tree[k *2+1] = max (TREE[K *2+1], tree[k]); TREE[K] =0; }}voidModifyintKintLeftintRightintL1,intR1,intx) {if(L1 <= left && right <= R1) {Tree[k] = max (tree[k], x);return; } pushdown (k);intMid = (left + right)/2;if(L1 < mid) modify (k *2, left, Mid, L1, R1, X);if(R1 > Mid) modify (k *2+1, Mid, right, L1, R1, x);}voidQueryintKintLeftintRightintL1,intR1) {if(Left +1= = right) {hh = tree[k];return; } pushdown (k);intMid = (left + right)/2;if(L1 < mid) query (k *2, left, Mid, L1, R1);ElseQuery (k *2+1, Mid, right, L1, R1);}intMain () {Freopen ("Input.txt","R", stdin); Freopen ("Output.txt","W", stdout);scanf("%d", &n);memset(Tree,0,sizeof(tree)); Mp.clear ();intCNT =0; for(inti =1; I <= N; i++) {scanf("%d%d%d", &h[i], &l[i], &r[i]);        a[cnt++] = L[i];    a[cnt++] = R[i];    } sort (A, a + CNT); CNT = Unique (A, A + CNT)-A; for(inti =0; I < CNT; i++) Mp[a[i]] = i; for(inti =1; I <= N; i++) Modify (1,0, CNT-1, Mp[l[i]], Mp[r[i]], h[i]);intnum =0, Curh =0; for(inti =0; I < CNT-1; i++) {Query (1,0, CNT-1, I, i +1);if(hh! = Curh) {res[num][0] = A[i]; res[num++][1] = Curh; res[num][0] = A[i]; res[num++][1] = hh;        Curh = hh; }    }if(CURH) {res[num][0] = a[cnt-1]; res[num++][1] = Curh; res[num][0] = a[cnt-1]; res[num++][1] =0; }printf("%d\n", num); for(inti =0; i < num; i++)printf("%d%d\n", res[i][0], res[i][1]);return 0;}

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Codeforces 35E (interval update)

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: 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.