There's a beach in the first quadrant. And from time to time, there are sea waves. A wave ( xx , yy) means the wave is a rectangle whose vertexes are ( 00 , 00 ), ( xx , 00 ), ( 00 , yy ), ( xx , yy ). Every time the wave will wash out the trace of former wave in its range and remain its own trace of ( xx , 00 ) -> ( xx , yy ) and ( 00 , yy ) -> ( xx , yy ). 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 \le 50000)n(n≤50000).

The next nn lines,each contains two numbers xxyy ,( 0 < x0<x , y \le 10000000y≤10000000 ),the ii-th line means the ii-th second there comes a wave of ( xx , yy ), it's guaranteed that when 1 \le i1≤i , j \le nj≤n,x_i \le x_jxi​≤xj​ and y_i \le y_jyi​≤yj​ 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=10

样例输入复制

3
1 4
4 1
3 3

样例输出复制

10

题目来源

ACM-ICPC 2018 徐州赛区网络预赛

题意:有n次海浪,每次海浪会产生两段轨迹(0,y)到(x,y)和(x,0)到(x,y),后面的海浪会将前面的在(0,0)到(x,y)之间区域的海浪轨迹覆盖掉,问最后剩余的轨迹长度

分析:每段轨迹有效的贡献是在此轨迹被接下来所有轨迹覆盖一次后剩余的轨迹长度

  所以我们考虑直接从后面往前面枚举

  最后的轨迹长度肯定是可以直接加上的,没有其余的海浪能覆盖掉他,然后将其的轨迹点放进集合

  接下来遍历到的点只要看集合里比他小的最大的数就是能覆盖掉他多少长度,减去这个长度就行

AC代码:

#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <queue>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <algorithm>
#define ls (r<<1)
#define rs (r<<1|1)
#define debug(a) cout << #a << " " << a << endl
using namespace std;
typedef long long ll;
const ll maxn = 1e5+10;
const ll mod = 2e9+7;
const double pi = acos(-1.0);
const double eps = 1e-8;
ll f( vector<ll> e ) {
ll sz = e.size(), ans = 0;
set<ll> s;
for( ll i = sz-1; i >= 0; i -- ) {
set<ll>::iterator it = s.lower_bound(e[i]);
if( it == s.begin() ) {
ans += e[i];
} else {
it --;
ans += e[i] - *it;
}
s.insert(e[i]);
}
return ans;
}
int main() {
ll x, y, n;
vector<ll> e1, e2;
scanf("%lld",&n);
while( n -- ) {
scanf("%lld%lld",&x,&y);
e1.push_back(x), e2.push_back(y);
}
printf("%lld\n",f(e1)+f(e2));
return 0;
}

  

Trace 2018徐州icpc网络赛 思维+二分的更多相关文章

  1. Trace 2018徐州icpc网络赛 (二分)(树状数组)

    Trace There's a beach in the first quadrant. And from time to time, there are sea waves. A wave ( xx ...

  2. Features Track 2018徐州icpc网络赛 思维

    Morgana is learning computer vision, and he likes cats, too. One day he wants to find the cat moveme ...

  3. Ryuji doesn't want to study 2018徐州icpc网络赛 树状数组

    Ryuji is not a good student, and he doesn't want to study. But there are n books he should learn, ea ...

  4. ICPC 2018 徐州赛区网络赛

    ACM-ICPC 2018 徐州赛区网络赛  去年博客记录过这场比赛经历:该死的水题  一年过去了,不被水题卡了,但难题也没多做几道.水平微微有点长进.     D. Easy Math 题意:   ...

  5. ACM-ICPC 2018 徐州赛区(网络赛)

    目录 A. Hard to prepare B.BE, GE or NE F.Features Track G.Trace H.Ryuji doesn't want to study I.Charac ...

  6. Supreme Number 2018沈阳icpc网络赛 找规律

    A prime number (or a prime) is a natural number greater than 11 that cannot be formed by multiplying ...

  7. 2019 徐州icpc网络赛 E. XKC's basketball team

    题库链接: https://nanti.jisuanke.com/t/41387 题目大意 给定n个数,与一个数m,求ai右边最后一个至少比ai大m的数与这个数之间有多少个数 思路 对于每一个数,利用 ...

  8. Trace 2018徐州赛区网络预赛

    题意: 每次给出一个点,然后就会形成两条线,如果后面的矩形覆盖了前面的边,那么这条边就消失了, 最后求剩下的边是多少 题目确保不会完全覆盖 也没有一个矩形在另一个矩形里面 即对于 X1,Y1  X2, ...

  9. ACM-ICPC 2018 徐州赛区网络预赛 G. Trace (思维,贪心)

    ACM-ICPC 2018 徐州赛区网络预赛 G. Trace (思维,贪心) Trace 问答问题反馈 只看题面 35.78% 1000ms 262144K There's a beach in t ...

随机推荐

  1. [NSNull intValue]: unrecognized selector sent to instance 0x375c9860

    今天遇到这个问题,程序崩溃了……日志如下: -[NSNull intValue]: unrecognized selector sent to instance 0x375c9860*** Termi ...

  2. Linux 文件系统相关的基本概念

    本文介绍 Linux 文件系统相关的基本概念. 硬盘的物理组成 盘片硬盘其实是由单个或多个圆形的盘片组成的,按照盘片能够容纳的数据量,分为单盘(一个硬盘里面只有一个盘片)或多盘(一个硬盘里面有多个盘片 ...

  3. MySQL中一些关于索引的知识点

    什么是索引 索引是一种数据结构,其作用就是用来提高数据查询效率.比较常用的比喻就是将其类比为书籍的目录.通过目录可以精确的找到某一章节的内容所在页. 在数据量较小的时候使用索引其实也没有什么意义,即使 ...

  4. java8-流的操作

    流的操作 流的使用一般包括三件事: 一个数据源来执行一个查询; 一个中间操作链,形成一条流的流水线; 一个终端操作,执行流水线,并能生成结果 中间操作 操作 类型 返回类型 操作参数 函数描述符 fi ...

  5. 【原创】JAVA进程突然消失的原因?

    引言 值此七夕佳节,烟哥放弃了无数妹纸的邀约,坐在电脑面前码字,就是为了给读者带来新的知识,这是一件伟大的事业! 好吧,实际情况是没人约.为了化解尴尬,我决定卖力写文章,嗯,一定是我过于屌丝! 好了, ...

  6. git的使用学习笔记

    一.git Git 是一个开源的分布式版本控制系统,项目版本管理工具,可以在本地提交修改再合并到主分支上,最为出色的是它的合并跟踪(merge tracing)能力. 可以通过Linux命令进行增加, ...

  7. 主成分分析 Principle Component Analysis

    一.主要思想 利用正交变换把可能线性相关变量表示的观测数据,转换为由少数几个线性无关变量(主成分)表示的数据.(重构原始特征空间:线性降维) 要尽可能保留原始数据中的信息,两个思路:最大投影方差.最小 ...

  8. 洛谷 P3413 SAC#1 - 萌数

    题意简述 求l~r之间存在长度至少为2的回文子串的正整数的个数 题解思路 数位DP 注意到有偶数长度的回文串必有长度为2的回文串,有奇数长度的回文串必有长度为3的回文串 所以只需判断与前一位,前两位是 ...

  9. 扩展GroupBox控件

    1.GroupBox的边框颜色可以自行设置: 2.GroupBox可以设置边框的为圆角: 3.设置GroupBox标题在控件中的位置. 4.设置GroupBox标题的字体和颜色. 具体实现步骤Pane ...

  10. 最短路径Dijkstra算法模板题---洛谷P3371 【模板】单源最短路径(弱化版)

    题目背景 本题测试数据为随机数据,在考试中可能会出现构造数据让SPFA不通过,如有需要请移步 P4779. 题目描述 如题,给出一个有向图,请输出从某一点出发到所有点的最短路径长度. 输入格式 第一行 ...