Advertisement
Galebickosikasa

Untitled

Jan 5th, 2021
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.75 KB | None | 0 0
  1. #include <bits/stdc++.h> //эм оккк
  2.  
  3. #define FASTER() ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  4. #define ff first
  5. #define ss second
  6. #define pb push_back
  7. #define all(a) a.begin(), a.end()
  8. #define int ll
  9.  
  10. typedef long long ll;
  11.  
  12. using namespace std;
  13.  
  14. const int mod1 = 12345, mod2 = 23456;
  15. const ll inf = LLONG_MAX - 1000;
  16.  
  17. struct segTree {
  18. vector <ll> mins, maxes;
  19. int sz = 1;
  20.  
  21. segTree(vector <ll> &v) {
  22. int n = v.size();
  23. while(sz < n) {
  24. sz <<= 1;
  25. }
  26. mins = vector <ll> (2 * sz - 1, inf);
  27. maxes = vector <ll> (2 * sz - 1, -inf);
  28. build(0, 0, sz, v);
  29. }
  30.  
  31. void build(int x, int lx, int rx, vector <ll> &v) {
  32. if(rx - lx == 1) {
  33. if(lx < (int)v.size()) {
  34. mins[x] = v[lx];
  35. maxes[x] = v[lx];
  36. }
  37. } else {
  38. int m = (lx + rx) >> 1;
  39. build(2 * x + 1, lx, m, v);
  40. build(2 * x + 2, m, rx, v);
  41. mins[x] = min(mins[2 * x + 1], mins[2 * x + 2]);
  42. maxes[x] = max(maxes[2 * x + 1], maxes[2 * x + 2]);
  43. }
  44. }
  45.  
  46. void upd(int x, int lx, int rx, int idx, int val) {
  47. if(rx - lx == 1) {
  48. mins[x] = val;
  49. maxes[x] = val;
  50. return;
  51. }
  52. int m = (lx + rx) >> 1;
  53. if(idx < m) {
  54. upd(2 * x + 1, lx, m, idx, val);
  55. } else {
  56. upd(2 * x + 2, m, rx, idx, val);
  57. }
  58. mins[x] = min(mins[2 * x + 1], mins[2 * x + 2]);
  59. maxes[x] = max(maxes[2 * x + 1], maxes[2 * x + 2]);
  60. }
  61.  
  62. void upd(int idx, int val) {
  63. upd(0, 0, sz, idx, val);
  64. }
  65.  
  66. pair <ll, ll> get(int x, int lx, int rx, int l, int r) { //1-st is min. 2nd - max
  67. if(lx >= r || rx <= l) {
  68. return {inf, -inf};
  69. }
  70. if(lx >= l && rx <= r) {
  71. return {mins[x], maxes[x]};
  72. }
  73. int m = (lx + rx) >> 1;
  74. auto ans1 = get(2 * x + 1, lx, m, l, r),
  75. ans2 = get(2 * x + 2, m, rx, l, r);
  76. ll mn = min(ans1.ff, ans2.ff);
  77. ll mx = max(ans1.ss, ans2.ss);
  78. return {mn, mx};
  79. }
  80.  
  81. ll get(int l, int r) {
  82. auto ans = get(0, 0, sz, l, r);
  83. return ans.ss - ans.ff;
  84. }
  85. };
  86.  
  87. signed main() {
  88. FASTER();
  89. int k;
  90. cin >> k;
  91. vector <pair <int, int>> q(k);
  92. int n = 1e5 + 20;
  93. vector <ll> v(n);
  94. for(int i = 1; i <= n; i++) {
  95. v[i - 1] = i * i % mod1 + i * i * i % mod2;
  96. }
  97. segTree st(v);
  98.  
  99. for(int i = 0; i < k; i++) {
  100. int x, y;
  101. cin >> x >> y;
  102. if(x < 0) {
  103. st.upd (-x - 1, y);
  104. } else {
  105. cout << st.get (x - 1, y) << '\n';
  106. }
  107. }
  108.  
  109. }
  110.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement