题意
选出三个不重叠区间。
思路
考虑贪心。
进行三次扫描。每次都选取(左端点比上个右端点大)的点之中的最小右端点。
因为右端点的扩大必然导致下一个区间选取范围的缩小,所以这么做是最优的。
代码
#include <stack>
#include <cstdio>
#include <list>
#include <cassert>
#include <set>
#include <fstream>
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <functional>
#include <cstring>
#include <algorithm>
#include <cctype>
#include <string>
#include <map>
#include <cmath>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/hash_policy.hpp>
using namespace std;
#define LL long long
#define ULL unsigned long long
#define SZ(x) (int)x.size()
#define Lowbit(x) ((x) & (-x))
#define MP(a, b) make_pair(a, b)
#define MS(arr, num) memset(arr, num, sizeof(arr))
#define PB push_back
#define X first
#define Y second
#define ROP freopen("input.txt", "r", stdin);
#define MID(a, b) (a + ((b - a) >> 1))
#define LC rt << 1, l, mid
#define RC rt << 1|1, mid + 1, r
#define LRT rt << 1
#define RRT rt << 1|1
#define FOR(i, a, b) for (int i=(a); (i) < (b); (i)++)
const double PI = acos(-1.0);
const int INF = 0x3f3f3f3f;
const double eps = 1e-8;
const int MAXN = 1e7+10;
const int MOD = 1e9;
const int dir[][2] = { {-1, 0}, {1, 0}, {0, -1}, {0, 1} };
const int seed = 131;
int cases = 0;
typedef pair<int, int> pii;
pair<unsigned int, unsigned int> p[MAXN];
int main()
{
//ROP;
int T;
scanf("%d", &T);
while (T--)
{
int n;
unsigned int L1, R1, a, b, c, d;
cin >> n >> p[1].X >> p[1].Y >> a >> b >> c >> d;
for (int i = 2; i <= n; i++)
{
p[i].X = p[i-1].X*a+b;
p[i].Y = p[i-1].Y*c+d;
}
for (int i = 1; i <= n; i++)
if (p[i].Y < p[i].X) swap(p[i].Y, p[i].X);
LL last_right = 0;
bool flag = false;
FOR(k, 0, 3)
{
ULL curAns = 0-1;
for (int i = 1; i <= n; i++)
{
if ((LL)p[i].X <= last_right) continue;
curAns = min(curAns, (ULL)p[i].Y);
}
if (curAns == 0ull-1)
{
flag = true;
break;
}
last_right = curAns;
}
puts(flag ? "NO" : "YES");
}
return 0;
}