不醒人室

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;

}

相关推荐
灵感__idea2 小时前
Hello 算法:贪心的世界
前端·javascript·算法
澈2073 小时前
深入浅出C++滑动窗口算法:原理、实现与实战应用详解
数据结构·c++·算法
ambition202424 小时前
从暴力搜索到理论最优:一道任务调度问题的完整算法演进历程
c语言·数据结构·c++·算法·贪心算法·深度优先
cmpxr_4 小时前
【C】原码和补码以及环形坐标取模算法
c语言·开发语言·算法
qiqsevenqiqiqiqi4 小时前
前缀和差分
算法·图论
代码旅人ing4 小时前
链表算法刷题指南
数据结构·算法·链表
Yungoal4 小时前
常见 时间复杂度计算
c++·算法
不爱吃炸鸡柳5 小时前
单链表专题(完整代码版)
数据结构·算法·链表
CylMK5 小时前
题解:AT_abc382_d [ABC382D] Keep Distance
算法
Dfreedom.6 小时前
计算机视觉全景图
人工智能·算法·计算机视觉·图像算法