2018 ACM-ICPC Xuzhou station network game title G

There's a beach in the first quadrant. And from time to time, there are sea waves. A wave ( xxx , yyy ) means the wave is a rectangle whose vertexes are ( 000 , 000 ), ( xxx , 000 ), ( 000 , yyy ), ( xxx , yyy ). Every time the wave will wash out the trace of former wave in its range and remain its own trace of ( xxx , 000 ) -> ( xxx , yyy ) and ( 000 , yyy ) -> ( xxx , yyy ). Now the toad on the coast wants to know the total length of trace on the coast after n waves. It's guaranteed that a wave will not cover the other completely.

Input

The first line is the number of waves n(n≤50000)n(n \le 50000)n(n50000).

The next nnn lines,each contains two numbers xxx yyy ,( 0<x0 < x0<x , y≤10000000y \le 10000000y10000000 ),the iii-th line means the iii-th second there comes a wave of ( xxx , yyy ), it's guaranteed that when 1≤i1 \le i1i , j≤nj \le njn ,xi≤xjx_i \le x_jxixj and yi≤yjy_i \le y_jyiyj don't set up at the same time.

Output

An Integer stands for the answer.

Hint:

As for the sample input, the answer is 3+3+1+1+1+1=103+3+1+1+1+1=103+3+1+1+1+1=10

Sample input

3
1 4
4 1
3 3

Sample Output

10

Source title

ACM-ICPC 2018 Xuzhou Division preliminaries network

Meaning of the questions:

There are n rectangles in order of appearance on the coordinate axis, the rectangle after the rectangle appears overrides occur before, the length of the last asked, is not covered (excluding the side coordinate axes).

analysis::

First seen this problem first thought should be the order of the rectangular join counted from the back side length. But also because the topics are requested: the absence of a rectangle is fully contained another rectangle, so that each has a rectangular protruding portion can be calculated within the answer. We enumerate forward from the rear rectangular, enumerated over the long side of the rectangle is added to the set, the newly added rectangle calculation method is to find the set according to the current edge length of the rectangle side length less than the current length of the longest side (two points), and then update the answer: ans + = (current edge - less than the current maximum set found in the side edges).

There is a note that point is two points when used upper_bound () use the set built, rather than a direct call STL, direct call STL, then the time is probably (around 1100ms TLE), use within set package upper_bound words long (90ms). . . . (Shock)

 

AC code:

#include<bits/stdc++.h>
using namespace std;
set<int> x;
set<int> y;
set<int>::iterator tx,ty;
int X[50005],Y[50005];

int main()
{
    int n;
    scanf("%d",&n);
    x.insert(0);
    y.insert(0);
    for(register int i=0;i<n;++i)
    { 
        Scanf ( " % D% D " , & X-[I], & the Y [I]); 
    } 
    Long  Long ANS = 0 ;
     for ( int I = N- . 1 ; I> = 0 ; - I) 
    { 
        TX = x.upper_bound (X-[I]); // provided with the package set-half 
        TX - ; 
        TY = y.upper_bound (the Y [I]); // provided with the package set-half
                 // * TY = (upper_bound, ( y.begin (), y.end (), Y [i])) timeout! ! ! ! 
        ty-- ; 
        ANS + = (X-[I] - * TX); 
        ANS+=(Y[i]-*ty);
        x.insert(X[i]);
        y.insert(Y[i]);
    }
    printf("%lld\n",ans);
    return 0;
}    

 

Guess you like

Origin www.cnblogs.com/cautx/p/11432558.html