【31.42%】【CF 714A】Meeting of Old Friends
1 second
256 megabytes
standard input
standard output
Today an outstanding event is going to happen in the forest — hedgehog Filya will come to his old fried Sonya!
Sonya is an owl and she sleeps during the day and stay awake from minute l1 to
minute r1 inclusive.
Also, during the minute k she prinks and is unavailable for Filya.
Filya works a lot and he plans to visit Sonya from minute l2 to
minute r2 inclusive.
Calculate the number of minutes they will be able to spend together.
The only line of the input contains integers l1, r1, l2, r2 and k (1 ≤ l1, r1, l2, r2, k ≤ 1018, l1 ≤ r1, l2 ≤ r2),
providing the segments of time for Sonya and Filya and the moment of time when Sonya prinks.
Print one integer — the number of minutes Sonya and Filya will be able to spend together.
1 10 9 20 1
2
1 100 50 200 75
50
In the first sample, they will be together during minutes 9 and 10.
In the second sample, they will be together from minute 50 to minute 74 and
from minute 76 to minute 100.
【题解】
求两个区间的交集。
很明显的线段树问题
(滑稽)
把两个区间的左端点的位置确定一下就好。
然后再看两个区间的右端点。
再判断k在不在交集中。
吧嗒吧嗒。。
【代码】
#include <cstdio> long long left1, right1, left2, right2, k,ans; void input_data()
{
scanf("%I64d%I64d%I64d%I64d%I64d", &left1, &right1, &left2, &right2, &k);
} void get_ans()
{
if (left1 > left2) //固定两个区间的左端点为从左到右
{
long long t = left1;
left1 = left2;
left2 = t;
t = right1;
right1 = right2;
right2 = t;
}
if (right1 < left2) //这是没有交集的情况。
printf("0\n");
else
if (right2 <= right1)
{
ans = right2 - left2 + 1;
if (left2 <= k && k <= right2)
ans--;
printf("%I64d\n", ans);
}
else
{
ans = right1 - left2 + 1;
if (left2 <= k && k <= right1)
ans--;
printf("%I64d\n", ans);
} } int main()
{
//freopen("F:\\rush.txt", "r", stdin);
input_data();
get_ans();
return 0;
}
【31.42%】【CF 714A】Meeting of Old Friends的更多相关文章
- 【codeforces】【比赛题解】#851 CF Round #432 (Div.2)
cf真的难…… 点我浏览丧题. [A]Arpa和她对墨西哥人浪的研究 Arpa正在对墨西哥人浪进行研究. 有n个人站成一排,从1到n编号,他们从时刻0开始墨西哥人浪. 在时刻1,第一个人站起来.在时刻 ...
- LeetCode:下一个更大元素I【31】
LeetCode:下一个更大元素I[31] 题目描述 给定两个没有重复元素的数组 nums1 和 nums2 ,其中nums1 是 nums2 的子集.找到 nums1 中每个元素在 nums2 中的 ...
- LeetCode:下一个排列【31】
LeetCode:下一个排列[31] 题目描述 实现获取下一个排列的函数,算法需要将给定数字序列重新排列成字典序中下一个更大的排列. 如果不存在下一个更大的排列,则将数字重新排列成最小的排列(即升序排 ...
- 剑指Offer:栈的压入、弹出序列【31】
剑指Offer:栈的压入.弹出序列[31] 题目描述 输入两个整数序列,第一个序列表示栈的压入顺序,请判断第二个序列是否为该栈的弹出顺序.假设压入栈的所有数字均不相等.例如序列1,2,3,4,5是某栈 ...
- JAVA 基础编程练习题42 【程序 42 求数字】
42 [程序 42 求数字] 题目:809*??=800*??+9*??+1 其中??代表的两位数,8*??的结果为两位数,9*??的结果为 3 位数.求??代表的两位数,及 809*??后的结 果. ...
- 【CF 453A】 A. Little Pony and Expected Maximum(期望、快速幂)
A. Little Pony and Expected Maximum time limit per test 1 second memory limit per test 256 megabytes ...
- 【实战Java高并发程序设计 3】带有时间戳的对象引用:AtomicStampedReference
[实战Java高并发程序设计 1]Java中的指针:Unsafe类 [实战Java高并发程序设计 2]无锁的对象引用:AtomicReference AtomicReference无法解决上述问题的根 ...
- 【Android】【录音】Android录音--AudioRecord、MediaRecorder
[Android][录音]Android录音--AudioRecord.MediaRecorder Android提供了两个API用于实现录音功能:android.media.AudioRecord. ...
- 【剑指Offer学习】【全部面试题汇总】
剑指Offer学习 剑指Offer这本书已经学习完了.从中也学习到了不少的东西,如今做一个总的文件夹.供自已和大家一起參考.学如逆水行舟.不进则退.仅仅有不断地学习才干跟上时候.跟得上技术的潮流! 全 ...
随机推荐
- 小爬爬5:scrapy介绍2
1.scrapy:爬虫框架 -框架:集成了很多功能且具有很强通用性的一个项目模板 -如何学习框架:(重点:知道有哪些模块,会用就行) -学习框架的功能模板的具体使用. 功能:(1)异步爬取(自带buf ...
- hdu3917 最大权闭合图
题意:有N个城市,M个公司.现在需要建立交通是获得的利益最大.如果2个公司A,B, A修的路为Xa->Ya,B的路为Xb->Yb,如果Ya==Xb,那么这2个公司有关系. 对于每个公司都有 ...
- vue_qqmapdemo1
腾讯地图vue组件,实现异步加载腾讯地图,坐标拾取器,支持按城市名称搜索. 搜索框样式依赖elementUI,不需要可删除顶部,地图部分无依赖项 //qqmap.vue <template> ...
- 阿里云DDoS高防的演进:防御效果成核心
分布式拒绝服务(DDoS)攻击这一网络公敌,是任何互联网业务的重大威胁.随着DDoS攻击工具化的发展,无论是简单野蛮的流量型攻击,还是复杂精巧的应用型攻击,黑客发起DDoS攻击变得越来越简单和自动化. ...
- django2.0基础
一.安装与项目的创建 1.安装 pip install django 2.查看版本 python -m django --version 3.创建项目 django-admin startprojec ...
- Hdu 1800 字符串hash
题目链接 题意: 给出n(n<=3000)个字符串(长度<30,数字组成,肯能存在前导0), 问该序列最少可以分成多少个单调序列.可以转化成求相同字符串的个数的最大值 附上代码: /*** ...
- Same Tree 深度优先
Given two binary trees, write a function to check if they are equal or not. Two binary trees are con ...
- POJ 2632 Crashing Robots (模拟 坐标调整)(fflush导致RE)
题目链接:http://poj.org/problem?id=2632 先话说昨天顺利1Y之后,直到今天下午才再出题 TAT,真是刷题计划深似海,从此AC是路人- - 本来2632是道略微恶心点的模拟 ...
- oracle中常用的时间格式转换
1:取得当前日期是本月的第几周 select to_char(sysdate,'YYYYMMDD W HH24:MI:SS') from dual; TO_CHAR(SYSDATE,'YY') se ...
- 使用iPhone为Apple Watch制作动画
(原文:Make Animations for APPLE WATCH Using iPhone 作者:Andy Drizen 译者:xiaoying) 无论要做一个像hamburger button ...