fork(2) download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define Foreach(i, c) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
  4. #define For(i,a,b) for(int (i)=(a);(i) < (b); ++(i))
  5. #define rof(i,a,b) for(int (i)=(a);(i) > (b); --(i))
  6. #define rep(i, c) for(auto &(i) : (c))
  7. #define x first
  8. #define y second
  9. #define pb push_back
  10. #define PB pop_back()
  11. #define iOS ios_base::sync_with_stdio(false)
  12. #define sqr(a) (((a) * (a)))
  13. #define all(a) a.begin() , a.end()
  14. #define error(x) cerr << #x << " = " << (x) <<endl
  15. #define Error(a,b) cerr<<"( "<<#a<<" , "<<#b<<" ) = ( "<<(a)<<" , "<<(b)<<" )\n";
  16. #define errop(a) cerr<<#a<<" = ( "<<((a).x)<<" , "<<((a).y)<<" )\n";
  17. #define coud(a,b) cout<<fixed << setprecision((b)) << (a)
  18. #define L(x) ((x)<<1)
  19. #define R(x) (((x)<<1)+1)
  20. #define umap unordered_map
  21. //#define max(x,y) ((x) > (y) ? (x) : (y))
  22. #define double long double
  23. typedef long long ll;
  24. typedef pair<int,int>pii;
  25. typedef vector<int> vi;
  26. typedef complex<double> point;
  27. ll A,B,n,l,t,m,s;
  28. inline ll comb(ll x){
  29. return (x * (x-1LL))/2LL;
  30. }
  31. inline ll h(ll i){
  32. return A + (i-1LL) * B;
  33. }
  34. inline bool check(ll r){
  35. ll e = comb(r) - comb(l-1LL);
  36. if(B && (double)e > 2e18 / (double)B)
  37. return false;
  38. if(h(r) > t) return false;
  39. s = m * t;
  40. s -= e * B;
  41. s -= A * (r - l + 1LL);
  42. return (s >= 0LL);
  43. }
  44. int main(){
  45. iOS;
  46. cin >> A >> B >> n;
  47. while(n --){
  48. cin >> l >> t >> m;
  49. if(h(l) > t){
  50. cout << -1 << '\n';
  51. continue;
  52. }
  53. ll lo = l, hi = max(t, m) + l + 5;
  54. while(lo < hi){
  55. ll mid = (lo + hi)/2LL;
  56. if(check(mid))
  57. lo = mid;
  58. else
  59. hi = mid - 1LL;
  60. if(lo + 1LL == hi){
  61. if(check(hi))
  62. lo = hi;
  63. else
  64. hi = lo;
  65. }
  66. }
  67. cout << lo << '\n';
  68. }
  69. }
  70.  
Success #stdin #stdout 0s 3276KB
stdin
Standard input is empty
stdout
Standard output is empty