SHARE
TWEET

Untitled

lalalalalalalaalalla Oct 21st, 2019 74 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<vector<int>> t, mod;
  57.  
  58. //void push(int ind, int v) {
  59. //    if (mod[ind][v] != -1) {
  60. //        mod[ind][2 * v + 1] = mod[ind][v];
  61. //        mod[ind][2 * v + 2] = mod[ind][v];
  62. //        mod[ind][v] = -1;
  63. //    }
  64. //}
  65.  
  66. //void cur(int ind, int v, int s) {
  67. //    t[ind][v] = (mod[ind][2 * v + 1] == -1 ? t[ind][2 * v + 1] : mod[ind][2 * v + 1] * s) + (mod[ind][2 * v + 2] == -1 ? t[ind][2 * v + 2] : mod[ind][2 * v + 2] * s);
  68. //}
  69.  
  70. //void update(int ind, int v, int l, int r, int askl, int askr, int val) {
  71. //    if (l >= askr || r <= askl) return;
  72. //    if (l >= askl && r <= askr) {
  73. //        mod[ind][v] = val;
  74. //        return;
  75. //    }
  76. //    push(ind, v);
  77. //    int m = (l + r) / 2;
  78. //    update(ind, 2 * v + 1, l, m, askl, askr, val);
  79. //    update(ind, 2 * v + 2, m, r, askl, askr, val);
  80. //    cur(ind, v, m - l);
  81. //}
  82.  
  83. //int get_sum(int ind, int v, int l, int r, int askl, int askr) {
  84. //    if (l >= askr || r <= askl) return 0;
  85. //    if (l >= askl && r <= askr) return (mod[ind][v] == -1 ? t[ind][v] : mod[ind][v] * (r - l));
  86. //    push(ind, v);
  87. //    int m = (l + r) / 2;
  88. //    int first = get_sum(ind, 2 * v + 1, l, m, askl, askr), second = get_sum(ind, 2 * v + 2, m, r, askl, askr);
  89. //    cur(ind, v, m - l);
  90. //    return first + second;
  91. //}
  92.  
  93. int n;
  94. vector<int> t, mod;
  95.  
  96. void push(int v) {
  97.     if (mod[v] != -1) {
  98.         mod[2 * v + 1] = mod[v];
  99.         mod[2 * v + 2] = mod[v];
  100.         mod[v] = -1;
  101.     }
  102. }
  103.  
  104. void node(int v, int s) {
  105.     t[v] = (mod[2 * v + 1] == -1 ? t[2 * v + 1] : mod[2 * v + 1] * s) + (mod[2 * v + 2] == -1 ? t[2 * v + 2] : mod[2 * v + 2] * s);
  106. }
  107.  
  108. void update(int v, int l, int r, int askl, int askr, int val) {
  109.     if (l >= askr || r <= askl) return;
  110.     if (l >= askl && r <= askr) {
  111.         mod[v] = val;
  112.         return;
  113.     }
  114.     push(v);
  115.     int m = (l + r) / 2;
  116.     update(2 * v + 1, l, m, askl, askr, val);
  117.     update(2 * v + 2, m, r, askl, askr, val);
  118.     node(v, m - l);
  119. }
  120.  
  121. int get_ans(int v, int l, int r, int askl, int askr) {
  122.     if (l >= askr || r <= askl) return 0;
  123.     if (l >= askl && r <= askr) return (mod[v] == -1 ? t[v] : mod[v] * (r - l));
  124.     push(v);
  125.     int m = (l + r) / 2;
  126.     int first = get_ans(2 * v + 1, l, m, askl, askr), second = get_ans(2 * v + 2, m, r, askl, askr);
  127.     node(v, m - l);
  128.     return first + second;
  129. }
  130.  
  131. signed main() {
  132.     ios_base::sync_with_stdio(0);
  133.     cin.tie(0);
  134.     cout.tie(0);
  135. //    cin >> n;
  136. //    t.resize(26, vector<int>(4 * n));
  137. //    mod.assign(26, vector<int>(4 * n, -1));
  138.  
  139.     freopen("sum.in", "r", stdin);
  140.     freopen("sum.out", "w", stdout);
  141.     cin >> n;
  142.     int q;
  143.     cin >> q;
  144.     t.resize(4 * n, 0);
  145.     mod.assign(4 * n, -1);
  146.     char type;
  147.     int l, r, val;
  148.     while(q--) {
  149.         cin >> type >> l >> r;
  150.         l--;
  151.         if (type == 'A') {
  152.             cin >> val;
  153.             update(0, 0, n, l, r, val);
  154.         } else {
  155.             cout << get_ans(0, 0, n, l, r) << "\n";
  156.         }
  157.     }
  158. }
  159. /*
  160.  
  161. 4 4
  162. 3 4 4 3
  163. 4 1 2 3
  164. 3 4 5 3
  165. 3 1 4 4
  166. -> 3
  167.  
  168. 4 5
  169. 2 2 2 2 2
  170. 2 1 1 2 2
  171. 2 2 2 1 1
  172. 2 2 2 2 2
  173. -> 2
  174. */
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top