题解:AT_abc434_c [ABC434C] Flapping Takahashi
题目大意
高桥初始在高度
思路
对于每一次的飞行,我们可以根据
具体来说,可以使用一个范围
最终时间复杂度为枚举区间的时间复杂度
AC Code
#include <iostream>
using namespace std;
const int N = 1e5+5;
struct Target //目标
{
int t,l,u;
}tar[N];
int n;
bool check(int h)
{
int l = h, r = h;
for (int i = 1; i <= n; i++)
{
int d = tar[i].t-tar[i-1].t;
if (r+d < tar[i].l || l-d > tar[i].u) return 0;
l = max(1,max(tar[i].l,l-d));
r = min(tar[i].u,r+d);
}
return 1;
}
int main()
{
int T;
cin >> T;
while (T--)
{
int h;
cin >> n >> h;
for (int i = 1; i <= n; i++) cin >> tar[i].t >> tar[i].l >> tar[i].u;
tar[0] = {0,h,h};
if (check(h)) cout << "Yes\n";
else cout << "No\n";
}
return 0;
}