题目
思路:
1、区间端点可能是小数的时候,不能直接利用加减1将 < 转化为 <=,例如,x < 1.5 不等价于 x <= 2.5
2、该题中k在(b - sqrt(4 * a * c), b + sqrt(4 * a * c) 中,注意是开区间,那么可以将左端点向上取整,右端点向下取整,即sqrt(4 * a * c)向下取整,计算出左右端点l,r,那么k在[l, r] 中(闭区间),如果4*a*c是平方数,那么l--, r++
3、最好把可能为小数的部分连同它的系数看成整体,若把4开根,那么sqrt(4 * a * c) == 2 * sqrt(a * c), 那么得再判断sqrt(a * c) 是不是 0.5结尾的,若是,那么2 * sqrt(a * c)还是整数
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define fi first
#define se second
#define lson p << 1
#define rson p << 1 | 1
const int maxn = 1e6 + 5, inf = 1e9, maxm = 4e4 + 5, mod = 1e9 + 7, N = 1e6;
int a[maxn], b[maxn];
int k[maxn];
// bool vis[maxn];
int n, m;
string s;int sqt(int x){int l = 0, r = inf;while(l <= r){int mid = (l + r) >> 1;if(mid * mid == x) return mid;else if(mid * mid < x) l = mid + 1;else r = mid - 1;}return r;
}
void solve(){int res = 0;// int k;int x;int q;int a, b, c;cin >> n >> m;for(int i = 1; i <= n; i++){cin >> k[i];}sort(k + 1, k + n + 1);for(int i = 1; i <= m; i++){cin >> a >> b >> c;if(c <= 0){cout << "No\n";continue;}int sq = sqrt(4 * a * c);int l = (b - sq), r = (b + sq);if(sq * sq == 4 * a * c){l++;r--;}int pos = lower_bound(k + 1, k + n + 1, l) - k;// cout << l << ' ' << r << '\n';if(pos <= n && k[pos] <= r){cout << "Yes\n";cout << k[pos] << '\n';}else cout << "No\n"; }cout << '\n';
}signed main(){ios::sync_with_stdio(0);cin.tie(0);int T = 1;cin >> T;while (T--){solve();}return 0;
}