不醒人室

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;

}

相关推荐
居7然30 分钟前
DeepSeek OCR:重新定义AI文档处理的“降本增效”新范式
人工智能·算法·语言模型·自然语言处理·大模型·ocr
while(1){yan}39 分钟前
数据结构之堆
数据结构·python·算法
SleepyWhite0011 小时前
代码随想录Day61|Floyd 算法精讲、A * 算法精讲
算法·floyd算法·astar算法
Miraitowa_cheems1 小时前
LeetCode算法日记 - Day 84: 乘积为正数的最长子数组长度
数据结构·算法·leetcode·贪心算法·线性回归·深度优先·动态规划
雾岛听蓝1 小时前
C语言:使用顺序表实现通讯录
c语言·数据结构·经验分享·笔记·visualstudio
不是老弟2 小时前
rwqsd
数据结构·c++·算法
小龙报2 小时前
《C语言疑难点 --- 字符函数和字符串函数专题(上)》
c语言·开发语言·c++·算法·学习方法·业界资讯·visual studio
程序员阿鹏2 小时前
560.和为k的子数组
数据结构
zbh06042 小时前
洛谷P5788 【模板】单调栈——单调栈
数据结构·算法