HihoCoder ——1305
来源:互联网 发布:淘宝禁售商品管理规范 编辑:程序博客网 时间:2024/06/10 21:35
hihocoder 1305
|A+B| = |A| + |B| - |AB|
|A-B| = |A| - |AB|
求出A,B,A+B 的实际长度,再用逻辑运算即可!
#include <bits/stdc++.h>typedef long long LL;using namespace std;const int maxn = 2e5 + 10;const int INF = 0x3f3f3f3f;pair <int,int> cntM[maxn];pair <int,int> cntN[maxn];pair <int,int> cntN_M[2*maxn];int main(){ int N,M; scanf("%d%d",&N,&M); for(int i = 0; i < N; i++) scanf("%d%d",&cntN[i].first,&cntN[i].second); for(int i = 0; i < M; i++) scanf("%d%d",&cntM[i].first,&cntM[i].second); for(int i = 0; i < N; i++) cntN_M[i] = cntN[i]; for(int i = 0; i < M; i++) cntN_M[i+N] = cntM[i]; sort(cntN,cntN+N); sort(cntM,cntM+M); sort(cntN_M,cntN_M+N+M); LL lena = 0,lenb = 0,lenc = 0; LL st = cntN[0].first; LL ed = cntN[0].second; for(int i = 1; i < N; i++) { if(cntN[i].first >= ed) {lena += (ed -st); st = cntN[i].first;ed = cntN[i].second;} else ed = max(ed,(LL)cntN[i].second); } lena += (ed -st); st = cntM[0].first; ed = cntM[0].second; for(int i = 0; i < M; i++) { if(cntM[i].first >= ed) {lenb += (ed -st); st = cntM[i].first;ed = cntM[i].second;} else ed = max(ed,(LL)cntM[i].second); } lenb += (ed -st); st = cntN_M[0].first; ed = cntN_M[0].second; for(int i = 0; i < N+M; i++) { if(cntN_M[i].first >= ed) {lenc += (ed -st); st = cntN_M[i].first;ed = cntN_M[i].second;} else ed = max(ed,(LL)cntN_M[i].second); } lenc += (ed -st); cout << lena - (lena + lenb - lenc) << endl ; return 0;}
阅读全文
0 0
- HihoCoder ——1305
- HihoCoder——Trie树
- 求割点割边——hihoCoder 1183
- DP——hihoCoder 1482
- hihoCoder挑战赛B题——计数
- hihoCoder挑战赛A题——顺子
- hihoCoder(1)——hiho密码
- 最小路径覆盖——hihoCoder 118
- 状压DP——hihoCoder 1044
- 状压DP——hihoCoder 1048
- 状态压缩——hihoCoder 1087
- 搜索起步—— Rectangle Split HihoCoder
- HihoCoder第十周——已知前序中序求后序
- HihoCoder第十二周——树上DP
- hihocoder—二维字符数组匹配
- hihocoder:
- hihoCoder
- Hihocoder
- tensorboard 的可视化 同得到train和validation的loss曲线
- redis cluster集群搭建与深入分析(1)
- C++完成日期类的实现——Date
- promise.then,process.nextTick, setTimeout 以及 setImmediate 的执行顺序
- H指数计算
- HihoCoder ——1305
- Java数据类型之时间
- maven 命令
- 介绍一个名为dragger的android控件
- 读取字符串中的数字
- 弱校胡策 银魂
- 单例模式应用之聊天界面
- 树状数组
- R语言数据挖掘(3)——关联分析