Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma GCC optimize("O3")
- #pragma GCC target("tune=native")
- #pragma GCC optimize("fast-math,unroll-loops")
- #include <math.h>
- #include <algorithm>
- #include <set>
- #include <iostream>
- #include <vector>
- #include <queue>
- #include <map>
- #include <string>
- #include <time.h>
- #include <cassert>
- #include <functional>
- #include <memory.h>
- #include <stack>
- #include <bitset>
- #include <unordered_map>
- #include <unordered_set>
- #include <random>
- #include <chrono>
- #include <complex>
- #include <fstream>
- #include <climits>
- using namespace std;
- typedef unsigned long long ull;
- typedef long long ll;
- typedef unsigned u;
- typedef long double ld;
- typedef vector<vector<int>> vvi;
- typedef unsigned char uc;
- typedef unsigned short us;
- typedef complex<double> cd;
- #define INF 1000000000
- #define LLINF 1000000000000000000LL
- #define EPS 1e-9l
- #define pii pair<int, int>
- const int DEBUG = 0;
- #ifdef LOCAL
- mt19937 gen(228);
- #else
- mt19937 gen((u)chrono::high_resolution_clock::now().time_since_epoch().count());
- #endif
- #pragma comment(linker, "/STACK:76777216")
- const int N = (int)1e5 + 100;
- struct node
- {
- ll mx, add;
- };
- node tree[4 * N];
- int a[N];
- int n;
- void build(int v, int tl, int tr)
- {
- if (tl > tr)
- return;
- if (tl == tr)
- {
- tree[v].mx = a[tl];
- return;
- }
- int tm = (tl + tr) / 2;
- build(2 * v, tl, tm);
- build(2 * v + 1, tm + 1, tr);
- tree[v].mx = max(tree[2 * v].mx, tree[2 * v + 1].mx);
- }
- void push(int v)
- {
- if (v < 2 * N)
- {
- tree[2 * v].mx += tree[v].add;
- tree[2 * v + 1].mx += tree[v].add;
- tree[2 * v].add += tree[v].add;
- tree[2 * v + 1].add += tree[v].add;
- }
- tree[v].add = 0;
- }
- void modify(int v, int tl, int tr, int l, int r, int x)
- {
- push(v);
- if (tr < l || tl > r)
- return;
- if (l <= tl && tr <= r)
- {
- tree[v].add += x;
- tree[v].mx += x;
- push(v);
- return;
- }
- int tm = (tl + tr) / 2;
- modify(2 * v, tl, tm, l, r, x);
- modify(2 * v + 1, tm + 1, tr, l, r, x);
- tree[v].mx = max(tree[2 * v].mx, tree[2 * v + 1].mx);
- }
- ll getMax(int v, int tl, int tr, int l, int r)
- {
- push(v);
- if (tr < l || tl > r)
- return -LLINF;
- if (l <= tl && tr <= r)
- return tree[v].mx;
- int tm = (tl + tr) / 2;
- return max(getMax(2 * v, tl, tm, l, r), getMax(2 * v + 1, tm + 1, tr, l, r));
- }
- int main()
- {
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- cout.setf(cout.fixed);
- cout.precision(12);
- auto START_TIME = chrono::high_resolution_clock::now();
- cin >> n;
- for (int i = 0; i < n; i++)
- {
- cin >> a[i];
- }
- build(1, 0, n - 1);
- int q;
- cin >> q;
- while (q--)
- {
- char c;
- cin >> c;
- if (c == 'a')
- {
- int l, r, x;
- cin >> l >> r >> x;
- --l; --r;
- modify(1, 0, n - 1, l, r, x);
- }
- else
- {
- int l, r;
- cin >> l >> r;
- --l; --r;
- cout << getMax(1, 0, n - 1, l, r) << " ";
- }
- }
- #ifdef LOCAL
- cerr.precision(3);
- cerr << "\nWorking time: " << chrono::duration<double>(chrono::high_resolution_clock::now() - START_TIME).count() << " sec.";
- #endif
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment