【题目链接】
【思路要点】
- 补档博客,无题解。
【代码】
#include<bits/stdc++.h> using namespace std; #define MAXN 100005 template <typename T> void read(T &x) { x = 0; int f = 1; char c = getchar(); for (; !isdigit(c); c = getchar()) if (c == '-') f = -f; for (; isdigit(c); c = getchar()) x = x * 10 + c - '0'; x *= f; } struct info {int x, y; }; int alen, blen; info a[MAXN], b[MAXN]; void get(int l, int r, int &tot, info *res) { int nxt = 0; tot = 0; for (int i = 1; i <= l; i = nxt + 1) { if (i == l) nxt = l; else nxt = (l - 1) / ((l - 1) / i); res[++tot] = (info) {(l - 1) / i + 1, r / i}; if (res[tot].x > res[tot].y) tot--; } } int main() { int T; read(T); while (T--) { int xl, xr, yl, yr; read(xl), read(xr), read(yl), read(yr); get(xl, xr, alen, a); get(yl, yr, blen, b); int now = 1, ans = 0; for (int i = 1; i <= alen; i++) { while (now <= blen && b[now].x > a[i].y) now++; if (now <= blen && max(b[now].x, a[i].x) <= min(b[now].y, a[i].y)) ans = max(ans, min(b[now].y, a[i].y)); } printf("%d\n", ans); } return 0; }