Codeforces 610D Vika and Segments

Source: Internet
Author: User

Topic Links:



Although it's a line segment, it's not considered so much if you write a rectangular area and write the rectangle directly.

But here's an extra explanation for the rectangular area and the line tree.

Note that a certain $-1 $ must be in this section $ +1 $ before the action will occur

So the mark is the number of times that this section has been "fully" overwritten and is not labeled as part of the modification

This is the first question to be used as a rectangular area.

1#include <cstdio>2#include <cstring>3#include <cmath>4#include <algorithm>5 using namespacestd;6 Const intN = 1e5 +Ten;7 structRec8 {9     intxa, ya, xb, YB;Ten }a[n]; One struct Line A { -     intx, ya, YB, num; -}b[n <<1]; the intHash[n <<1]; - intSum[n <<3], Flag[n <<3]; - intN; - Long LongAns =0; + BOOLCMP (ConstLine &aa,ConstLine &BB) - { +     returnAa.x <bb.x; A } at voidPushup (intXintTlintTR) - { -     if(Flag[x]) -SUM[X] = hash[tr +1] -HASH[TL]; -     Else if(TL! =TR) -SUM[X] = sum[x <<1] + sum[x <<1|1]; in     Else -SUM[X] =0; to     return; + } - voidUpdateintXintLintRintTlintTrintnum) the { *     if(L <= tl && R >=TR) $     {Panax NotoginsengFLAG[X] + =num; - pushup (x, TL, TR); the         return; +     } A     intMid = (tl + TR) >>1; the     if(L <=mid) +Update (x <<1, L, R, TL, Mid, num); -     if(R >mid) $Update (x <<1|1, L, R, Mid +1, TR, num); $ pushup (x, TL, TR); - } - intMain () the { -scanf"%d", &n);Wuyi      for(inti =1; I <= N; ++i) the     { -scanf"%d%d%d%d", &a[i].xa, &a[i].ya, &AMP;A[I].XB, &a[i].yb); Wu         if(A[i].xa >A[I].XB) - swap (A[i].xa, A[I].XB); About         if(A[i].ya >A[i]. YB) $ swap (A[i].ya, a[i].yb); -++A[I].XB; -++A[i].yb; -Hash[i *2-1] =A[i].ya; AHash[i *2] =A[i].yb; +B[i *2-1].x =A[i].xa; theB[i *2-1].num =1; -B[i *2].x =A[I].XB; $B[i *2].num =-1; theB[i *2].ya = B[i *2-1].ya =A[i].ya; theB[i *2].YB = B[i *2-1].yb =A[i].yb; the     } theSort (hash +1, hash +1+ N *2); -Sort (b +1, B +1+ N *2, CMP); inb[0].x = b[1].x; the      for(inti =1; I <= N *2; ++i) the     { About         intL, R; theL = Lower_bound (hash +1, hash +1+ N *2, B[i].ya)-Hash; theR = Lower_bound (hash +1, hash +1+ N *2, B[I].YB)-Hash-1; theAns + = (Long Long) (B[i].x-b[i-1].x) * sum[1]; +Update1, L, R,1N2-1, b[i].num); -     } theprintf"%lld\n", ans);Bayi     return 0; the}

Codeforces 610D Vika and Segments

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.