不醒人室

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;

}

相关推荐
PAK向日葵2 小时前
【算法导论】PDD 0817笔试题题解
算法·面试
地平线开发者5 小时前
ReID/OSNet 算法模型量化转换实践
算法·自动驾驶
地平线开发者5 小时前
开发者说|EmbodiedGen:为具身智能打造可交互3D世界生成引擎
算法·自动驾驶
星星火柴9366 小时前
关于“双指针法“的总结
数据结构·c++·笔记·学习·算法
艾莉丝努力练剑7 小时前
【洛谷刷题】用C语言和C++做一些入门题,练习洛谷IDE模式:分支机构(一)
c语言·开发语言·数据结构·c++·学习·算法
闪电麦坤958 小时前
数据结构:迭代方法(Iteration)实现树的遍历
数据结构·二叉树·
C++、Java和Python的菜鸟9 小时前
第六章 统计初步
算法·机器学习·概率论
Cx330❀9 小时前
【数据结构初阶】--排序(五):计数排序,排序算法复杂度对比和稳定性分析
c语言·数据结构·经验分享·笔记·算法·排序算法
散1129 小时前
01数据结构-Prim算法
数据结构·算法·图论
起个昵称吧9 小时前
线程相关编程、线程间通信、互斥锁
linux·算法