不醒人室

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;

}

相关推荐
User_芊芊君子18 分钟前
【C语言经典算法实战】:从“移动距离”问题看矩阵坐标计算
c语言·算法·矩阵
wolf犭良1 小时前
37、aiomysql实操习题
开发语言·python·算法
xin007hoyo2 小时前
算法笔记.spfa算法(bellman-ford算法的改进)
数据结构·笔记·算法
向哆哆2 小时前
Java 加密与解密:从算法到应用的全面解析
java·开发语言·算法
uhakadotcom2 小时前
刚发布的PyTorch 2.7提供了什么 新特性
算法·面试·github
新生农民3 小时前
30分钟解决8道算法题
java·数据结构·算法
bbc1212263 小时前
2025/4/23 心得
数据结构·算法
Brookty4 小时前
【数据结构】Map与Set结构详解
数据结构
WaitWaitWait017 小时前
LeetCode每日一题4.20
算法·leetcode
蒟蒻小袁7 小时前
力扣面试150题--有效的括号和简化路径
算法·leetcode·面试