Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <bits/stdc++.h>
- #define all(x) begin(x), end(x)
- #define rall(x) rbegin(x), rend(x)
- #define file "sum"
- using namespace std;
- using ll = long long;
- using ull = unsigned long long;
- using str = string;
- using srt = short;
- const int INF = (int)1e9 + 7;
- const int MOD = 998244353;
- const ll inf = (ll)2e18;
- const ll mod = (int)1e9 + 7;
- const int N = 1000 + 5;
- int n, m;
- vector<int> tree;
- void push(int v)
- {
- if (tree[v] != -1)
- {
- tree[v * 2] = tree[v * 2 + 1] = tree[v];
- tree[v] = -1;
- }
- }
- void upd(int l, int r, int x, int v = 1, int tl = 0, int tr = n - 1)
- {
- if (l > r)
- return;
- if (tl == l && tr == r)
- {
- tree[v] = x;
- return;
- }
- int tm = tl + tr >> 1;
- push(v);
- upd(l, min(tm, r), x, v * 2, tl, tm);
- upd(max(tm + 1, l), r, x, v * 2 + 1, tm + 1, tr);
- }
- ll sum(int l, int r, int v = 1, int tl = 0, int tr = n - 1)
- {
- if (l > r)
- return 0;
- if (tree[v] != -1)
- {
- return 1LL * tree[v] * (r - l + 1);
- }
- if (tl == l && tr == r)
- {
- int tm = tl + tr >> 1;
- return 0LL + sum(tl, tm, v * 2, tl, tm) + sum(tm + 1, tr, v * 2 + 1, tm + 1, tr);
- }
- int tm = tl + tr >> 1;
- push(v);
- return 0LL + sum(l, min(r, tm), v * 2, tl, tm) + sum(max(l, tm + 1), r, v * 2 + 1, tm + 1, tr);
- }
- int main()
- {
- //freopen("input.txt", "r", stdin);
- //freopen("output.txt", "w", stdout);
- ios::sync_with_stdio(0); cin.tie(nullptr); cout.tie(nullptr); freopen(file".in", "r", stdin); freopen(file".out", "w", stdout);
- cin >> n >> m;
- tree.resize(4 * n, 0);
- for (int i = 0; i < m; ++i)
- {
- char op;
- cin >> op;
- if (op == 'A')
- {
- int l, r, x;
- cin >> l >> r >> x;
- l--; r--;
- upd(l, r, x);
- }
- else
- {
- int l, r;
- cin >> l >> r;
- l--; r--;
- cout << sum(l, r) << endl;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement