不醒人室

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;

}

相关推荐
xingzhemengyou19 分钟前
C语言 查找一个字符在字符串中第i次出现的位置
c语言·算法
冰清-小魔鱼1 小时前
各类数据存储结构总结
开发语言·数据结构·数据库
小六子成长记2 小时前
【C++】:搜索二叉树的模拟实现
数据结构·c++·算法
汉克老师2 小时前
GESP2025年9月认证C++二级真题与解析(编程题1(优美的数字))
c++·算法·整除·枚举算法·求余·拆数
Zevalin爱灰灰3 小时前
现代控制理论——第二章 系统状态空间表达式的解
线性代数·算法·现代控制
菜鸟233号3 小时前
力扣377 组合总和 Ⅳ java实现
java·数据结构·算法·leetcode
我是大咖3 小时前
二级指针与指针数组搭配
c语言·数据结构·算法
葫三生4 小时前
三生原理范畴语法表明中国哲学可为算法母语
人工智能·深度学习·算法·transformer
D_FW4 小时前
数据结构第五章:树与二叉树
数据结构·算法
WHS-_-20224 小时前
Tx and Rx IQ Imbalance Compensation for JCAS in 5G NR
javascript·算法·5g