Codeforces Round #371 (Div. 2) A. Meeting of Old Friends (水题)
2016-09-14 09:45
1041 查看
题目点我点我点我
A. Meeting of Old Friends
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
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.
Input
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.
Output
Print one integer — the number of minutes Sonya and Filya will be able to spend together.
Examples
input
output
input
output
Note
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.
A. Meeting of Old Friends
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
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.
Input
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.
Output
Print one integer — the number of minutes Sonya and Filya will be able to spend together.
Examples
input
1 10 9 20 1
output
2
input
1 100 50 200 75
output
50
Note
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.
/* *********************************************** ┆ ┏┓ ┏┓ ┆ ┆┏┛┻━━━┛┻┓ ┆ ┆┃ ┃ ┆ ┆┃ ━ ┃ ┆ ┆┃ ┳┛ ┗┳ ┃ ┆ ┆┃ ┃ ┆ ┆┃ ┻ ┃ ┆ ┆┗━┓ 马 ┏━┛ ┆ ┆ ┃ 勒 ┃ ┆ ┆ ┃ 戈 ┗━━━┓ ┆ ┆ ┃ 壁 ┣┓┆ ┆ ┃ 的草泥马 ┏┛┆ ┆ ┗┓┓┏━┳┓┏┛ ┆ ┆ ┃┫┫ ┃┫┫ ┆ ┆ ┗┻┛ ┗┻┛ ┆ ************************************************ */ #include <stdio.h> #include <string.h> #include <iostream> #include <algorithm> #include <vector> #include <queue> #include <stack> #include <set> #include <map> #include <string> #include <math.h> #include <stdlib.h> #include <bitset> using namespace std; #define rep(i,a,b) for (int i=(a),_ed=(b);i<=_ed;i++) #define per(i,a,b) for (int i=(b),_ed=(a);i>=_ed;i--) #define pb push_back #define mp make_pair const int inf_int = 2e9; const long long inf_ll = 2e18; #define inf_add 0x3f3f3f3f #define mod 1000000007 #define LL long long #define ULL unsigned long long #define MS0(X) memset((X), 0, sizeof((X))) #define SelfType int SelfType Gcd(SelfType p,SelfType q){return q==0?p:Gcd(q,p%q);} SelfType Pow(SelfType p,SelfType q){SelfType ans=1;while(q){if(q&1)ans=ans*p;p=p*p;q>>=1;}return ans;} #define Sd(X) int (X); scanf("%d", &X) #define Sdd(X, Y) int X, Y; scanf("%d%d", &X, &Y) #define Sddd(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z) #define reunique(v) v.resize(std::unique(v.begin(), v.end()) - v.begin()) #define all(a) a.begin(), a.end() typedef pair<int, int> pii; typedef pair<long long, long long> pll; typedef vector<int> vi; typedef vector<long long> vll; inline int read(){int ra,fh;char rx;rx=getchar(),ra=0,fh=1;while((rx<'0'||rx>'9')&&rx!='-')rx=getchar();if(rx=='-')fh=-1,rx=getchar();while(rx>='0'&&rx<='9')ra*=10,ra+=rx-48,rx=getchar();return ra*fh;} //#pragma comment(linker, "/STACK:102400000,102400000") int main() { //freopen("in.txt","r",stdin); //freopen("out.txt","w",stdout); ios::sync_with_stdio(0); cin.tie(0); LL l1,l2,r1,r2,k; cin>>l1>>r1>>l2>>r2>>k; LL L = max(l1,l2); LL R = min(r1,r2); LL ans = R-L+1; if(k>=L && k<=R)ans--; if(ans<0)ans = 0; cout<<ans<<endl; return 0; }
相关文章推荐
- HDU 5876 Sparse Graph
- dhcp_start
- Linux CentOS下EPEL源的安装
- win10系统安装pyopencl攻略
- which、whereis、locate、find 命令用法
- VS2015实用小技巧---设置启动依赖项
- js操作下拉框
- android4.4(kitkat),如何让APP可以直接写入SMS短信
- 竞价之关键词
- c# 文件日志处理 需要log4net配置
- windows redis:Uncaught exception 'RedisException' with message 'Redis server went away'
- 如何在视频播放页面单独打开横屏
- 本地仓库少了jar包,maven项目加载的时候报错
- 移动轨迹显示博客
- Codeforces Round #371 (Div. 2)
- 工作经常用到的Mac软件整理
- 效能分析——词频统计第一版
- c# 处理js序列化时 datetime返回UTC格式的问题
- css入门
- BZOJ 3262 陌上花开