本题直接对每个区间取并,若出现非法区间就是No 否则就是Yes
#include<bits/stdc++.h> using namespace std; #define lowbit(x) ((x)&(-x)) typedef long long LL; LL t[105], l[105], h[105]; void run_case() { int n; LL m; cin >> n >> m; for(int i = 1; i <= n; ++i) cin >> t[i] >> l[i] >> h[i]; LL Left = m, Right = m; for(int i = 1; i <= n; ++i) { LL times = t[i] - t[i-1]; Left = max(l[i], Left-times); Right = min(h[i], Right+times); if(Left > Right) { cout << "NO "; return; } } if(Left <= Right) cout << "YES "; else cout << "NO "; } int main() { ios::sync_with_stdio(false), cin.tie(0); //cout.setf(ios_base::showpoint);cout.precision(10); int t; cin >> t; while(t--) run_case(); cout.flush(); return 0; }