不醒人室

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;

}

相关推荐
Magnum Lehar1 小时前
vulkan游戏引擎test_manager实现
java·算法·游戏引擎
水蓝烟雨2 小时前
[面试精选] 0094. 二叉树的中序遍历
算法·面试精选
超闻逸事2 小时前
【题解】[UTPC2024] C.Card Deck
c++·算法
暴力求解2 小时前
C++类和对象(上)
开发语言·c++·算法
JKHaaa2 小时前
几种简单的排序算法(C语言)
c语言·算法·排序算法
让我们一起加油好吗2 小时前
【基础算法】枚举(普通枚举、二进制枚举)
开发语言·c++·算法·二进制·枚举·位运算
FogLetter2 小时前
微信红包算法揭秘:从随机性到产品思维的完美结合
算法
YGGP3 小时前
吃透 Golang 基础:数据结构之 Map
开发语言·数据结构·golang
BUG收容所所长3 小时前
二分查找的「左右为难」:如何优雅地找到数组中元素的首尾位置
前端·javascript·算法
weixin_419658313 小时前
数据结构之栈
数据结构