lalalalalalalaalalla

Untitled

Oct 21st, 2019
73
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <vector>
  3. #include <string>
  4. #include <iomanip>
  5. #include <queue>
  6. #include <cmath>
  7. #include <algorithm>
  8. #include <tuple>
  9. #include <iomanip>
  10. #include <stdio.h>
  11. #include <numeric>
  12. #include <map>
  13. #include <bitset>
  14. #include <set>
  15. #include <stack>
  16. #include <queue>
  17. #include <unordered_set>
  18.  
  19.  
  20. //#pragma GCC optimize("Ofast,no-stack-protector")
  21. #pragma GCC optimize("O3")
  22. //#pragma GCC target("avx2")
  23. //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
  24. #pragma GCC optimize("unroll-loops")
  25. //#pragma GCC optimize("fast-math")
  26. //#pragma GCC optimize("section-anchors")
  27. //#pragma GCC optimize("profile-values,profile-reorder-functions,tracer")
  28. //#pragma GCC optimize("vpt")
  29. //#pragma GCC optimize("rename-registers")
  30. //#pragma GCC optimize("move-loop-invariants")
  31. //#pragma GCC optimize("unswitch-loops")
  32. //#pragma GCC optimize("function-sections")
  33. //#pragma GCC optimize("data-sections")
  34. //#pragma GCC optimize("branch-target-load-optimize")
  35. //#pragma GCC optimize("branch-target-load-optimize2")
  36. //#pragma GCC optimize("btr-bb-exclusive")
  37. //#pragma GCC optimize("O0")
  38.  
  39.  
  40. #define int long long
  41. #define ll long long
  42. #define ull unsigned long long
  43. #define all(a) a.begin(), a.end()
  44. #define pii pair<int, int>
  45. #define pb push_back
  46. #define ld long double
  47.  
  48.  
  49. using namespace std;
  50.  
  51. const int INF = 1e17;
  52. //const int mod = 2600000069;
  53. //const int p = 179;
  54.  
  55. int n;
  56. vector<int> t, mod;
  57.  
  58. void push(int v) {
  59. if (mod[v] != INF) {
  60. mod[2 * v + 1] = mod[v];
  61. mod[2 * v + 2] = mod[v];
  62. mod[v] = INF;
  63. }
  64. }
  65.  
  66. void norm(int v, int s) {
  67. t[v] = 0;
  68. if (mod[2 * v + 1] != INF) {
  69. t[v] += mod[2 * v + 1] * s;
  70. } else t[v] += t[2 * v + 1];
  71. if (mod[2 * v + 2] != INF) {
  72. t[v] += mod[2 * v + 2] * s;
  73. } else t[v] += t[2 * v + 2];
  74. }
  75.  
  76. void update(int v, int l, int r, int askl, int askr, int val) {
  77. if (l >= askr || r <= askl) return;
  78. if (l >= askl && r <= askr) {
  79. mod[v] = val;
  80. return;
  81. }
  82. push(v);
  83. int m = (l + r) / 2;
  84. update(2 * v + 1, l, m, askl, askr, val);
  85. update(2 * v + 2, m, r, askl, askr, val);
  86. norm(v, m - l);
  87. }
  88.  
  89. int get_ans(int v, int l, int r, int askl, int askr) {
  90. if (l >= askr || r <= askl) return 0;
  91. if (l >= askl && r <= askr) {
  92. if (mod[v] != INF) {
  93. return mod[v] * (r - l);
  94. }
  95. return t[v];
  96. }
  97. push(v);
  98. int m = (l + r) / 2;
  99. int first = get_ans(2 * v + 1, l, m, askl, askr), second = get_ans(2 * v + 2, m, r, askl, askr);
  100. norm(v, m - l);
  101. return first + second;
  102. }
  103.  
  104. signed main() {
  105. ios_base::sync_with_stdio(0);
  106. cin.tie(0);
  107. cout.tie(0);
  108. freopen("sum.in", "r", stdin);
  109. freopen("sum.out", "w", stdout);
  110. cin >> n;
  111. t.assign(4 * n, 0);
  112. mod.assign(4 * n, INF);
  113. int q;
  114. cin >> q;
  115. char w;
  116. int l, r, val;
  117. while(q--) {
  118. cin >> w >> l >> r;
  119. --l;
  120. if (w == 'A') {
  121. cin >> val;
  122. update(0, 0, n, l, r, val);
  123. } else cout << get_ans(0, 0, n, l, r) << "\n";
  124. }
  125. }
  126. /*
  127.  
  128. */
RAW Paste Data