Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #pragma GCC optimize("O3")
- #pragma GCC optimize("unroll-loops")
- #include <ext/pb_ds/assoc_container.hpp>
- #include <ext/pb_ds/tree_policy.hpp>
- #define all(x) x.begin(), x.end()
- #define rall(x) x.rbegin(), x.rend()
- #define GLHF ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL)
- #define f first
- #define s second
- #define eb emplace_back
- #define pb push_back
- #define ppb pop_back
- #define pf push_front
- #define ppf pop_front
- #define len(a) (int)a.size()
- using namespace std;
- using namespace __gnu_pbds;
- typedef long long ll;
- typedef long double ld;
- const ll MOD = 1e9 + 7;
- const int INF = 1e9;
- const int N = 2e5 + 2;
- mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
- ll T1;
- void timer()
- {
- ll T2(clock());
- cout << "Exec time: " << (T2-T1) << "ms" << endl;
- }
- template<class A, class B> ostream& operator << (ostream& out, const pair<A, B>& a)
- {
- out << "(" << a.x << ", " << a.y << ")";
- }
- template<class A> ostream& operator << (ostream& out, const vector<A>& a)
- {
- out << "[";
- for(auto it = a.begin(); it != a.end(); ++it)
- {
- if(it != a.begin()) out << ", ";
- out << *it;
- }
- out << "]";
- }
- template<class A> ostream& operator << (ostream& out, const set<A>& a)
- {
- out << "{";
- for(auto it = a.begin(); it != a.end(); ++it)
- {
- if(it != a.begin()) out << ", ";
- out << *it;
- }
- out << "}";
- }
- template<class A, class B> ostream& operator << (ostream& out, const map<A, B>& a)
- {
- out << "{" << endl;
- for(auto it = a.begin(); it != a.end(); ++it)
- {
- out << " " << it->x << ": " << it->y;
- if(it != a.end()) out << ", ";
- out << endl;
- }
- out << "}";
- }
- template<class A> istream& operator >> (istream& in, vector<A>& a)
- {
- for(auto &e : a)
- in >> e;
- return in;
- }
- template<class A, class B> istream& operator >> (istream& in, pair<A, B>& a)
- {
- in >> a.x >> a.y;
- return in;
- }
- ll binpow(ll a, ll n)
- {
- if(n == 0) return 1;
- if(n % 2) return (binpow(a, n - 1) * a) % MOD;
- else
- {
- ll b = binpow(a, n / 2);
- return (b * b) % MOD;
- }
- }
- //GOOD LUCK BEWARE OF INDIAN HACKERS
- ll t[4 * N], m[4 * N], k[4 * N];
- vector<int> a(N);
- void push(int v, int tl, int tr)
- {
- if(m[v] != -1)
- {
- m[v * 2] = m[v * 2 + 1] = m[v];
- m[v] = -1;
- int tm = (tr + tl) / 2;
- t[v * 2] = (tm - tl + 1) * 1ll * m[v * 2];
- t[v * 2 + 1] = (tr - tm) * 1ll * m[v * 2 + 1];
- }
- if(k[v] != -1)
- {
- k[v * 2] = k[v * 2 + 1] = k[v];
- k[v] = -1;
- int tm = (tl + tr) / 2;
- t[v * 2] += (tm - tl + 1) * 1ll * k[v * 2];
- t[v * 2 + 1] += (tr - tm) * 1ll * k[v * 2 + 1];
- }
- }
- void build(int v, int tl, int tr)
- {
- if(tl == tr)
- {
- t[v] = a[tl];
- m[v] = a[tl];
- k[v] = 0;
- return;
- }
- push(v, tl, tr);
- int tm = (tl + tr) / 2;
- build(v * 2, tl, tm);
- build(v * 2 + 1, tm + 1, tr);
- t[v] = t[v * 2] + t[v * 2 + 1];
- }
- ll sum(int v, int tl, int tr, int l, int r)
- {
- if(tl > r || tr < l)
- return 0;
- if(l == tl && r == tr)
- return t[v];
- push(v, tl, tr);
- int tm = (tl + tr) / 2;
- return sum(v * 2, tl, tm, l, min(r, tm)) +
- sum(v * 2 + 1, tm + 1, tr, max(tm + 1, l), r);
- }
- void add(int v, int tl, int tr, int l, int r, int val)
- {
- if(tl > r || tr < l)
- return;
- if(l == tl && r == tr)
- {
- k[v] = val;
- m[v] = -1;
- t[v] += (tr - tl + 1) * 1ll * val;
- return;
- }
- push(v, tl, tr);
- int tm = (tl + tr) / 2;
- add(v * 2, tl, tm, l, min(tm, r), val);
- add(v * 2 + 1, tm + 1, tr, max(tm + 1, l), r, val);
- t[v] = t[v * 2] + t[v * 2 + 1];
- }
- void upd(int v, int tl, int tr, int l, int r, int val)
- {
- if(tl > r || tr < l)
- return;
- if(l == tl && r == tr)
- {
- m[v] = val;
- k[v] = -1;
- t[v] = (tr - tl + 1) * 1ll * val;
- return;
- }
- push(v, tl, tr);
- int tm = (tl + tr) / 2;
- upd(v * 2, tl, tm, l, min(r, tm), val);
- upd(v * 2 + 1, tm + 1, tr, max(tm + 1, l), r, val);
- t[v] = t[v * 2] + t[v * 2 + 1];
- }
- int main()
- {
- GLHF;
- int n, q;
- cin >> n >> q;
- for(int i = 1; i <= n; ++i)
- cin >> a[i];
- build(1, 1, n);
- while(q--)
- {
- int i, x, y;
- cin >> i >> x >> y;
- if(i == 1)
- {
- int b;
- cin >> b;
- add(1, 1, n, x, y, b);
- }
- else if(i == 2)
- {
- int b;
- cin >> b;
- upd(1, 1, n, x, y, b);
- }
- else
- cout << sum(1, 1, n, x, y) << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement