二分。
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #define maxn 200500 #define inf 3000000000LL using namespace std; long long t,n,s[maxn],e[maxn],d[maxn],cnt; long long find(long long x) { long long ret=0; for (long long i=1;i<=n;i++) { if (x>e[i]) ret+=(e[i]-s[i])/d[i]+1; else if (x>=s[i]) ret+=(x-s[i])/d[i]+1; } return ret; } void work() { scanf("%lld",&n);cnt=0; for (long long i=1;i<=n;i++) scanf("%lld%lld%lld",&s[i],&e[i],&d[i]); long long l=1,r=inf,ans=-1; while (l<=r) { long long mid=l+r>>1,ret=find(mid); if (ret%2) {ans=mid;r=mid-1;} else l=mid+1; } if (ans==-1) printf("Poor QIN Teng:( "); else { for (int i=1;i<=n;i++) { if ((ans>=s[i]) && (ans<=e[i]) && ((ans-s[i])%d[i]==0)) cnt++; } printf("%lld %lld ",ans,cnt); } } int main() { scanf("%lld",&t); for (long long i=1;i<=t;i++) work(); return 0; }