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. // Ваня топ
  21.  
  22.  
  23. #define int long long
  24. #define ll long long
  25. #define ull unsigned long long
  26. #define all(a) a.begin(), a.end()
  27. #define pii pair<int, int>
  28. #define pb push_back
  29. #define ld long double
  30.  
  31.  
  32. using namespace std;
  33.  
  34. const int INF = 1e17;
  35. //const int mod = 2600000069;
  36. //const int p = 179;
  37.  
  38. int n;
  39. vector<int> t, mod;
  40.  
  41. void push(int v, int s) {
  42.     if (mod[v] != INF) {
  43.         t[v] = mod[v] * s;
  44.         mod[2 * v + 1] = mod[v];
  45.         mod[2 * v + 2] = mod[v];
  46.         mod[v] = INF;
  47.     }
  48. }
  49.  
  50. void update(int v, int l, int r, int askl, int askr, int val) {
  51.     if (l >= askr || r <= askl) return;
  52.     push(v, r - l);
  53.     if (l >= askl && r <= askr) {
  54.         mod[v] = val;
  55.         push(v, r - l);
  56.         return;
  57.     }
  58.     int m = (l + r) / 2;
  59.     update(2 * v + 1, l, m, askl, askr, val);
  60.     update(2 * v + 2, m, r, askl, askr, val);
  61.     t[v] = t[2 * v + 1] + t[2 * v + 2];
  62. }
  63.  
  64. int get_ans(int v, int l, int r, int askl, int askr) {
  65.     if (l >= askr || r <= askl) return 0;
  66.     push(v, r - l);
  67.     if (l >= askl && r <= askr) {
  68.         return t[v];
  69.     }
  70.     int m = (l + r) / 2;
  71.     int first = get_ans(2 * v + 1, l, m, askl, askr), second = get_ans(2 * v + 2, m, r, askl, askr);
  72.     return first + second;
  73. }
  74.  
  75. signed main() {
  76.     ios_base::sync_with_stdio(0);
  77.     cin.tie(0);
  78.     cout.tie(0);
  79. //    freopen("sum.in", "r", stdin);
  80. //    freopen("sum.out", "w", stdout);
  81.     cin >> n;
  82.     t.assign(4 * n, 0);
  83.     mod.assign(4 * n, INF);
  84.     int q;
  85.     cin >> q;
  86.     char w;
  87.     int l, r, val;
  88.     while(q--) {
  89.         cin >> w >> l >> r;
  90.         --l;
  91.         if (w == 'A') {
  92.             cin >> val;
  93.             update(0, 0, n, l, r, val);
  94.         } else cout << get_ans(0, 0, n, l, r) << "\n";
  95.     }
  96. }
  97. /*
  98.  
  99. */
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