fork download
  1. //#pragma GCC optimize("O3,unroll-loops")
  2. //#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
  3.  
  4. #include <bits/stdc++.h>
  5. using namespace std;
  6.  
  7. #define file "o"
  8. #define ff(i, a, b) for(auto i=(a); i<=(b); ++i)
  9. #define ffr(i, b, a) for(auto i=(b); i>=(a); --i)
  10. #define nl "\n"
  11. #define ss " "
  12. #define pb emplace_back
  13. #define fi first
  14. #define se second
  15. #define sz(s) (int)s.size()
  16. #define all(s) (s).begin(), (s).end()
  17. #define ms(a,x) memset(a, x, sizeof (a))
  18. #define cn continue
  19. #define re exit(0)
  20.  
  21. typedef long long ll;
  22. typedef unsigned long long ull;
  23. typedef long double ld;
  24. typedef vector<int> vi;
  25. typedef vector<ll> vll;
  26. typedef pair<int, int> pii;
  27. typedef pair<ll, ll> pll;
  28. typedef vector<pii> vpii;
  29. typedef vector<pll> vpll;
  30.  
  31. mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
  32. ll ran(ll l, ll r)
  33. {
  34. return uniform_int_distribution<ll> (l, r)(rng);
  35. }
  36.  
  37. inline void rf()
  38. {
  39. ios_base::sync_with_stdio(false);
  40. cin.tie(nullptr); cout.tie(nullptr);
  41. if(fopen(file".inp","r"))
  42. {
  43. freopen(file".inp","r",stdin);
  44. freopen(file".out","w",stdout);
  45. }
  46. }
  47.  
  48. const int mod=998244353;
  49. const int maxn=2e5+15;
  50. const ll inf=1e16;
  51.  
  52. template<typename T> inline void add(T &x, const T &y)
  53. {
  54. x+=y;
  55. if(x>=mod) x-=mod;
  56. if(x<0) x+=mod;
  57. }
  58.  
  59. template<typename T> inline bool maxi(T &a, T b)
  60. {
  61. if(a>=b) return 0;
  62. a=b; return 1;
  63. }
  64.  
  65. template<typename T> inline bool mini(T &a, T b)
  66. {
  67. if(a<=b) return 0;
  68. a=b; return 1;
  69. }
  70.  
  71. ll ans[maxn];
  72.  
  73. typedef __int128_t i128;
  74.  
  75. inline bool check(ll a, ll b, ll n, ll h)
  76. {
  77. if(n==1) return (h<=a);
  78. return h-a<=(i128)(a-b)*(n-1);
  79. }
  80.  
  81. inline ll get(ll a, ll b, ll h)
  82. {
  83. ll l=1, r=1e18, id=-1;
  84. while(l<=r)
  85. {
  86. ll mid=(l+r)>>1;
  87. if(check(a, b, mid, h) ) id=mid, r=mid-1;
  88. else l=mid+1;
  89. }
  90. return id;
  91. }
  92.  
  93. void solve()
  94. {
  95. int q; cin>>q;
  96. ff(i, 1, q) ans[i]=-1;
  97. ll l=1, r=1e18;
  98. ff(id, 1, q)
  99. {
  100. ll op, a, b; cin>>op>>a>>b;
  101. if(op==1)
  102. {
  103. ll n; cin>>n;
  104. if(n==1)
  105. {
  106. if(l>a) ans[id]=0;
  107. else ans[id]=1, mini(r, a);
  108. }
  109. else
  110. {
  111. ll mn=(a-b)*(n-2)+a+1, mx=(a-b)*(n-1)+a;
  112. if(mn>r || mx<l) ans[id]=0;
  113. else ans[id]=1, maxi(l, mn), mini(r, mx);
  114. }
  115. }
  116. else
  117. {
  118. if(l==r) ans[id]=get(a, b, l);
  119. else
  120. {
  121. ll mn=get(a, b, l), mx=get(a, b, r);
  122. if(mn==mx) ans[id]=mn;
  123. else ans[id]=-1;
  124. }
  125. }
  126. }
  127. ff(i, 1, q) cout<<ans[i]<<ss;
  128. cout<<nl;
  129. }
  130.  
  131. signed main()
  132. {
  133. rf();
  134. int tt=1; cin>>tt;
  135. while(tt--) solve();
  136. re;
  137. }
  138.  
  139.  
  140.  
  141.  
Success #stdin #stdout 0s 544KB
stdin
5
3
1 3 2 5
2 4 1
2 3 2
3
1 6 5 1
2 3 1
2 6 2
3
1 4 2 2
1 2 1 3
2 10 2
9
1 7 3 6
1 2 1 8
2 5 1
1 10 9 7
1 8 1 2
1 10 5 8
1 10 7 7
2 7 4
1 9 4 2
9
1 2 1 6
1 8 5 6
1 4 2 7
2 9 1
1 5 1 4
1 5 2 7
1 7 1 9
1 9 1 4
2 10 8
stdout
1 2 5 
1 -1 1 
1 0 1 
1 0 -1 0 0 0 1 8 0 
1 0 0 1 0 0 0 0 1