题目链接:https://codeforces.com/problemset/status?my=on
按时间排序,集合取交集
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<cmath>
#include<stack>
#include<queue>
using namespace std;
typedef long long ll;
const int maxn = 200;
int q,n,m;
struct P{
int t,l,r;
}p[maxn];
bool cmp(P a,P b){ return a.t < b.t; }
ll read(){ ll s=0,f=1; char ch=getchar(); while(ch<'0' || ch>'9'){ if(ch=='-') f=-1; ch=getchar(); } while(ch>='0' && ch<='9'){ s=s*10+ch-'0'; ch=getchar(); } return s*f; }
int main(){
q = read();
while(q--){
n = read(), m = read();
int low = m, high = m;
for(int i=1;i<=n;++i){ p[i].t = read(), p[i].l = read(), p[i].r = read(); }
sort(p+1,p+1+n,cmp);
int f = 0;
for(int i=1;i<=n;++i){
low -= p[i].t - p[i-1].t, high += p[i].t - p[i-1].t;
if(low > p[i].r || high < p[i].l){
printf("NO
");
f = 1;
break;
}
low = max(low, p[i].l); high = min(high, p[i].r);
}
if(!f) printf("YES
");
}
return 0;
}