Air Conditioner - 洛谷https://www.luogu.com.cn/problem/CF1304C
给定了初始温度,可以考虑维护一段室内空调的区间即[l-t,r+t]然后再根据每一时刻的客人适应的温度区间进行修改区间,如果当其不能再适应客人的区间时即为NO,否则为YES。
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <cstring>
#include <set>
#include <unordered_map>
#include <cmath>
#include <map>
#include <cctype>
#include <cstdlib>
#include <deque>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
const int MN = 65005;
const int MAXN = 1e6 + 5;
const int INF = 0x3f3f3f3f;
#define IOS ios::sync_with_stdio(false)
#define lowbit(x) ((x)&(-x))
struct node {
int t, l, r;
};
node s[MAXN];
inline void solve() {
int n, m;
scanf("%d %d", &n, &m);
for (int i = 1; i <= n; i++) {
scanf("%d %d %d", &s[i].t, &s[i].l, &s[i].r);
}
bool flag = true;
int l = m, r = m;
for (int i = 1; i <= n; i++) {
int d = s[i].t - s[i - 1].t;
l = max(l - d, s[i].l);
r = min(r + d, s[i].r);
if (l > r) {
flag = false;
break;
}
}
if (flag)
printf("YES\n");
else
printf("NO\n");
}
int main() {
int t;
scanf("%d", &t);
while (t--)
solve();
return 0;
}