SHARE
TWEET

Untitled

lalalalalalalaalalla Oct 21st, 2019 77 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, int s) {
  59.     if (mod[v] != INF) {
  60.         t[v] = mod[v] * s;
  61.         mod[2 * v + 1] = mod[v];
  62.         mod[2 * v + 2] = mod[v];
  63.         mod[v] = INF;
  64.     }
  65. }
  66.  
  67. void update(int v, int l, int r, int askl, int askr, int val) {
  68.     if (l >= askr || r <= askl) return;
  69.     push(v, r - l);
  70.     if (l >= askl && r <= askr) {
  71.         t[v] = val * (r - l);
  72.         mod[v] = val;
  73.         return;
  74.     }
  75.     int m = (l + r) / 2;
  76.     update(2 * v + 1, l, m, askl, askr, val);
  77.     update(2 * v + 2, m, r, askl, askr, val);
  78.     t[v] = t[2 * v + 1] + t[2 * v + 2];
  79. }
  80.  
  81. int get_ans(int v, int l, int r, int askl, int askr) {
  82.     if (l >= askr || r <= askl) return 0;
  83.     push(v, r - l);
  84.     if (l >= askl && r <= askr) {
  85.         return t[v];
  86.     }
  87.     int m = (l + r) / 2;
  88.     int first = get_ans(2 * v + 1, l, m, askl, askr), second = get_ans(2 * v + 2, m, r, askl, askr);
  89.     t[v] = t[2 * v + 1] + t[2 * v + 2];
  90.     return first + second;
  91. }
  92.  
  93. signed main() {
  94.     ios_base::sync_with_stdio(0);
  95.     cin.tie(0);
  96.     cout.tie(0);
  97. //    freopen("sum.in", "r", stdin);
  98. //    freopen("sum.out", "w", stdout);
  99.     cin >> n;
  100.     t.assign(4 * n, 0);
  101.     mod.assign(4 * n, INF);
  102.     int q;
  103.     cin >> q;
  104.     char w;
  105.     int l, r, val;
  106.     while(q--) {
  107.         cin >> w >> l >> r;
  108.         --l;
  109.         if (w == 'A') {
  110.             cin >> val;
  111.             update(0, 0, n, l, r, val);
  112.         } else cout << get_ans(0, 0, n, l, r) << "\n";
  113.     }
  114. }
  115. /*
  116.  
  117. */
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
 
Top