不醒人室

1004 不醒人室 (hdu.edu.cn)

#include<bits/stdc++.h>

#define int long long

using namespace std;

const int N = 2e5+10;

int n, m;

struct node{

int l, r, s;

}st[N];

bool cmp(node x, node y){

return x.l < y.l;

}

void solve(){

int cnt = 0;

cin >> n >> m;

for(int i = 0; i < n; i ++){

int x, y;

cin >> x >> y;

st[cnt ++] = {x, y, 1};

}

for(int i = 0; i < m; i ++){

int x, y;

cin >> x >> y;

st[cnt ++] = {x, y, 0};

}

sort(st, st+cnt, cmp);

for(int i = 1; i < cnt; i ++){

if(st[i].l < st[i-1].r){

cout << "No\n";

return ;

}

}

int x = 0;

for(int i = 0; i < cnt; i ++){

if(st[i].s)

{

if(x < st[i].r)

{

cout << "No\n";

return ;

}

}

else

{

x = st[i].r+2*(st[i].r-st[i].l);

}

}

cout << "Yes\n";

}

signed main(){

ios::sync_with_stdio(0);

cin.tie(0), cout.tie(0);

int T = 1;

cin >> T;

while(T --){

solve();

}

return 0;

}

相关推荐
爱吃rabbit的mq14 分钟前
第09章:随机森林:集成学习的威力
算法·随机森林·集成学习
(❁´◡`❁)Jimmy(❁´◡`❁)1 小时前
Exgcd 学习笔记
笔记·学习·算法
YYuCChi1 小时前
代码随想录算法训练营第三十七天 | 52.携带研究材料(卡码网)、518.零钱兑换||、377.组合总和IV、57.爬楼梯(卡码网)
算法·动态规划
不能隔夜的咖喱2 小时前
牛客网刷题(2)
java·开发语言·算法
VT.馒头2 小时前
【力扣】2721. 并行执行异步函数
前端·javascript·算法·leetcode·typescript
进击的小头2 小时前
实战案例:51单片机低功耗场景下的简易滤波实现
c语言·单片机·算法·51单片机
咖丨喱3 小时前
IP校验和算法解析与实现
网络·tcp/ip·算法
罗湖老棍子4 小时前
括号配对(信息学奥赛一本通- P1572)
算法·动态规划·区间dp·字符串匹配·区间动态规划
fengfuyao9854 小时前
基于MATLAB的表面织构油润滑轴承故障频率提取(改进VMD算法)
人工智能·算法·matlab
机器学习之心4 小时前
基于随机森林模型的轴承剩余寿命预测MATLAB实现!
算法·随机森林·matlab