Advertisement
Galebickosikasa

Untitled

Jan 5th, 2021
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.46 KB | None | 0 0
  1. // #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
  2. // #pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.1,sse4.2,popcnt,abm,mmx,avx")
  3. // #pragma comment(linker, "/stack:200000000"]
  4.  
  5. #include <iostream>
  6. #include <vector>
  7. #include <cmath>
  8. #include <algorithm>
  9. #include <unordered_set>
  10. #include <unordered_map>
  11. #include <set>
  12. #include <map>
  13. #include <queue>
  14. #include <deque>
  15. #include <bitset>
  16. #include <stack>
  17. #include <random>
  18. #include <fstream>
  19. #include <sstream>
  20. #include <chrono>
  21.  
  22. #define fi first
  23. #define se second
  24. #define pb push_back
  25. #define ll long long
  26. #define ld long double
  27. #define hm unordered_map
  28. #define pii pair<int, int>
  29. #define sz(a) (int)a.size()
  30. #define all(a) a.begin(), a.end()
  31. #define cinv(v) for (auto& x: v) cin >> x
  32. #define fr(i, n) for (int i = 0; i < n; ++i)
  33. #define fl(i, l, n) for (int i = l; i < n; ++i)
  34.  
  35. #define int ll
  36.  
  37. template <typename T1, typename T2> inline bool chkmin(T1 &x, const T2 &y) {if (x > y) {x = y; return 1;} return 0;}
  38. template <typename T1, typename T2> inline bool chkmax(T1 &x, const T2 &y) {if (x < y) {x = y; return 1;} return 0;}
  39.  
  40. using namespace std;
  41.  
  42. #ifdef LOCAL
  43. #define dbg(x) cerr << #x << " : " << x << '\n'
  44. const int maxn = 20;
  45. #else
  46. #define dbg(x)
  47. const int maxn = 2e5 + 20;
  48. #endif
  49.  
  50. //tg: @galebickosikasa
  51.  
  52. ostream& operator << (ostream& out, const pii& v) {
  53. out << v.fi << ", " << v.se;
  54. return out;
  55. }
  56.  
  57. template<typename T> ostream& operator << (ostream& out, const vector<T>& v) {
  58. for (auto& x: v) out << x << " ";
  59. return out;
  60. }
  61.  
  62. istream& operator >> (istream& in, pii& a) {
  63. in >> a.fi >> a.se;
  64. return in;
  65. }
  66.  
  67. const ll inf = (ll) 2e9;
  68. const ld pi = asin (1) * 2;
  69. const ld eps = 1e-8;
  70. const ll mod = (ll)1e9 + 7;
  71. const ll ns = 97;
  72.  
  73. mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
  74.  
  75. struct tree {
  76. vector<int> mx, mn;
  77. int size = 1, capacity;
  78.  
  79. tree (vector<int>& v) {
  80. while ((1<<size) < sz (v)) ++size;
  81. ++size;
  82. size = (1<<size);
  83. capacity = (size>>1);
  84. mx = vector<int> (size, -inf);
  85. mn = vector<int> (size, inf);
  86. fr (i, sz (v)) mx[i + capacity] = mn[i + capacity] = v[i];
  87. for (int i = capacity - 1; i > 0; --i) {
  88. mx[i] = max (mx[i * 2], mx[i * 2 + 1]);
  89. mn[i] = min (mn[i * 2], mn[i * 2 + 1]);
  90. }
  91. }
  92.  
  93. pii get (int cur, int left, int right, int l, int r) {
  94. pii ptt = {inf, -inf};
  95. if (cur >= size) return ptt;
  96. if (left > r || right < l) return ptt;
  97. if (l <= left && r >= right) return {mn[cur], mx[cur]};
  98. auto ptt1 = get (cur * 2, left, (left + right) / 2, l, r);
  99. auto ptt2 = get (cur * 2 + 1, (left + right) / 2 + 1, right, l, r);
  100. ptt.fi = min (ptt1.fi, ptt2.fi);
  101. ptt.se = max (ptt1.se, ptt2.se);
  102. return ptt;
  103. }
  104.  
  105. inline int get (int l, int r) {
  106. auto ptt = get (1, 0, capacity - 1, l, r);
  107. return ptt.se - ptt.fi;
  108. }
  109.  
  110. inline void set (int i, int x) {
  111. i += capacity;
  112. mn[i] = mx[i] = x;
  113. i >>= 1;
  114. while (i) {
  115. mn[i] = min (mn[i * 2], mn[i * 2 + 1]);
  116. mx[i] = max (mx[i * 2], mx[i * 2 + 1]);
  117. i >>= 1;
  118. }
  119. }
  120. };
  121.  
  122. signed main () {
  123. ios_base::sync_with_stdio(false);
  124. cin.tie(nullptr);
  125. cout.tie(nullptr);
  126. int n = 1e5 + 20;
  127. vector<int> goo (n);
  128. fl (i, 1, n + 1) goo[i - 1] = i * i % 12345 + i * i * i % 23456;
  129. tree t (goo);
  130. int q;
  131. cin >> q;
  132. while (q--) {
  133. int x, y;
  134. cin >> x >> y;
  135. if (x > 0) {
  136. --x, --y;
  137. cout << t.get (x, y) << '\n';
  138. } else {
  139. x *= -1;
  140. --x;
  141. t.set (x, y);
  142. }
  143. }
  144.  
  145.  
  146.  
  147.  
  148.  
  149.  
  150.  
  151. }
  152.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement