https://www.luogu.org/problem/show?pid=CF1029C

 #include<bits/stdc++.h>
using namespace std ;
#define LL long long LL read(){
char c ;
int sign = ;
while((c = getchar()) > '' || c < '')
if(c == '-') sign = - ;
LL ans = c - '' ;
while((c = getchar()) <='' && c >= '')
ans = ans * + c - '' ;
return ans * sign ;
} int n ;
LL l[] , r[] ;
LL la = , ra = 10e9 + ; void answer(){
la = , ra = 10e9 + ;
for(int i = ; i <= n ; ++ i){
la = max(la , l[i]) ;
ra = min(ra , r[i]) ;
}
} int main(){
n = read() ;
LL ansl = , ansr = ;
r[] = 10e9 + ;
l[] = ;
for(int i = ; i <= n ; ++ i){
l[i] = read() , r[i] = read() ;
}
answer() ;
if(la > ra) {
printf("%d",);
return ;
}
for(int i = ; i <= n ; ++ i){
if(l[i] == la){
if(r[i] < r[ansl]) {
ansl = i ;
}
}
if(r[i] == ra){
if(l[i] > l[ansr]){
ansr = i ;
}
}
}
if(ansr == ansl){
l[ansr] = ;
r[ansr] = 10e9 + ;
answer() ;
printf("%ld",ra - la) ;
return ;
}
else {
LL ii = l[ansr] ;
LL ff = r[ansr] ;
l[ansr] = , r[ansr] = 10e9 + ;
answer() ;
LL len = ra - la ;
l[ansr] = ii , r[ansr] = ff ;
l[ansl] = , r[ansl] = 10e9 + ;
answer() ;
len = max(len , ra - la) ;
printf("%ld",len) ;
return ;
}
}

CF1029C Maximal Intersection的更多相关文章

  1. CF1029C Maximal Intersection 暴力枚举

    Maximal Intersection time limit per test 3 seconds memory limit per test 256 megabytes input standar ...

  2. Codeforces Round #506 (Div. 3) C. Maximal Intersection

    C. Maximal Intersection time limit per test 3 seconds memory limit per test 256 megabytes input stan ...

  3. Codeforces | CF1029C 【Maximal Intersection】

    论Div3出这样巨水的送分题竟然还没多少人AC(虽说当时我也没A...其实我A了D...逃) 这个题其实一点都不麻烦,排序都可以免掉(如果用\(priority \_ queue\)的话) 先考虑不删 ...

  4. CodeForces C. Maximal Intersection

    http://codeforces.com/contest/1029/problem/C You are given nn segments on a number line; each endpoi ...

  5. F - Maximal Intersection --------暴力求解题

    You are given n segments on a number line; each endpoint of every segment has integer coordinates. S ...

  6. C. Maximal Intersection(STL)

    这道题,关键在于怎么求多个区间的交集,使用multiset就可以 分别将 r , l 存在不同的mutiset中. 然后,我们来看一下 是不是 交集的 l 是最大的, 交集的 r 是最小的 #incl ...

  7. CF C. Maximal Intersection(贪心 || STL)

    题意 给你N个线段(一条直线上),问删去一个之后,最长公共长度 : 分析:首先我们得先知道n条线段公共的线段一定是(LMAX,RMIN) ,那我们可以先排序,然后枚举删除边: #include< ...

  8. Codeforces Round #506 (Div. 3) 题解

    Codeforces Round #506 (Div. 3) 题目总链接:https://codeforces.com/contest/1029 A. Many Equal Substrings 题意 ...

  9. cf 1029 C

    C. Maximal Intersection time limit per test 3 seconds memory limit per test 256 megabytes input stan ...

随机推荐

  1. Joda-Time 的 DateTimeFormat 问题

    在开发过程中遇到的问题是,当我使用,如下的代码时,会报异常 :"Exception in thread "main" org.joda.time.IllegalField ...

  2. Linux Ubuntu系统之PPP拨号经验分享

    近期,工作需要,我负责开发PPP拨号模块. 说起拨号,算算时间,我已经做过2次了, 暴露年龄了,呵呵. 第一次是刚毕业做的PPOE拨号,给电信做拨号软件,在河北石家庄工作过一段时间,基于windows ...

  3. windows黑窗口关于java程序的常用命令

    1.启动java程序 我要运行:E:\code\nhtask下的ElectricEye-0.0.1-SNAPSHOT.jar程序 #切换到程序目录cd E:\code\nhtaskE: java -j ...

  4. ASP.Net 页面和后台执行的先后顺序

    后台的Page_Load事件——>前台页面加载

  5. [转]Todd.log - a place to keep my thoughts on programming 分布式架构中的幂等性

    Todd.log - a place to keep my thoughts on programming 理解HTTP幂等性 基于HTTP协议的Web API是时下最为流行的一种分布式服务提供方式. ...

  6. idea远程debug:tomcat

    在tomcat的bin/startup.sh中添加: 27780debug的端口 declare -x CATALINA_OPTS="-server -Xdebug -Xnoagent -D ...

  7. BZOJ4939: [Ynoi2016]掉进兔子洞(莫队 bitset)

    题意 题目链接 一个长为 n 的序列 a. 有 m 个询问,每次询问三个区间,把三个区间中同时出现的数一个一个删掉,问最后三个区间剩下的数的个数和,询问独立. 注意这里删掉指的是一个一个删,不是把等于 ...

  8. zblog忘记后台密码怎么办 官方解决方案

    刚装的zblog还没开始研究,结果发现密码弄错了进不去后台,也是醉了 为节省时间,直接用官方方案,就是一个无密码进后台的文件.下载后把文件上传至网站根目录,然后直接访问后台修改密码 zblog密码找回 ...

  9. 数据库迁移后报错提示MySQL Error:Can''t find file errno: 13 - Permission denied的解决方法

    用户MYSQL数据库迁移后,遇到报错MySQL Error:Can't find file (errno: 13 - Permission denied)使用以下指令重新设置所有者和权限,依然不能解决 ...

  10. xmlHttpRequest在Firefox下不起作用?

    描述: XMLHttpRequest 在IE下正常,在Firefox下不起作用. 原因: XMLHttpRequest 对象的 onreadystatechange 不会在Firefox下执行, 解放 ...