不醒人室

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;

}

相关推荐
LGL6030A2 小时前
算法题实战积累(3)——方块转换(C语言)
c语言·算法
一条星星鱼3 小时前
深度学习是如何收敛的?梯度下降算法原理详解
人工智能·深度学习·算法
努力写代码的熊大4 小时前
List迭代器和模拟(迭代器的模拟)
数据结构·windows·list
长路归期无望6 小时前
C语言小白实现多功能计算器的艰难历程
c语言·开发语言·数据结构·笔记·学习·算法
MobotStone6 小时前
AI训练的悖论:为什么越追求准确率越会产生幻觉?
算法
怀旧,8 小时前
【C++】26. 智能指针
开发语言·c++·算法
dragoooon348 小时前
[优选算法专题三.二分查找——NO.24搜索旋转排序数组中的最⼩值]
数据结构·leetcode·动态规划
Haooog8 小时前
654.最大二叉树(二叉树算法)
java·数据结构·算法·leetcode·二叉树
Swift社区8 小时前
LeetCode 392 判断子序列
算法·leetcode·职场和发展
芒果量化8 小时前
ML4T - 第7章第8节 利用LR预测股票价格走势Predicting stock price moves with Logistic Regression
算法·机器学习·线性回归