Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <string>
- #include <iomanip>
- #include <queue>
- #include <cmath>
- #include <algorithm>
- #include <tuple>
- #include <iomanip>
- #include <stdio.h>
- #include <numeric>
- #include <map>
- #include <bitset>
- #include <set>
- #include <stack>
- #include <queue>
- #include <unordered_set>
- #include <cassert>
- //#pragma GCC optimize("Ofast,no-stack-protector")
- #pragma GCC optimize("O3")
- //#pragma GCC target("avx2")
- //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native")
- //#pragma GCC optimize("unroll-loops")
- #pragma GCC optimize("fast-math")
- //#pragma GCC optimize("section-anchors")
- //#pragma GCC optimize("profile-values,profile-reorder-functions,tracer")
- //#pragma GCC optimize("vpt")
- //#pragma GCC optimize("rename-registers")
- //#pragma GCC optimize("move-loop-invariants")
- //#pragma GCC optimize("unswitch-loops")
- //#pragma GCC optimize("function-sections")
- //#pragma GCC optimize("data-sections")
- //#pragma GCC optimize("branch-target-load-optimize")
- //#pragma GCC optimize("branch-target-load-optimize2")
- //#pragma GCC optimize("btr-bb-exclusive")
- //#pragma GCC optimize("O0")
- #define int long long
- #define ll long long
- #define ull unsigned long long
- #define all(a) a.begin(), a.end()
- #define pii pair<int, int>
- #define pb push_back
- #define ld long double
- using namespace std;
- //const int INF = 1e13;
- //const int mod = 2600000069;
- //const int p = 179;
- int n;
- vector<int> a, t, mod;
- void build(int v, int l, int r) {
- if (r - l == 1) {
- t[v] = a[l];
- return;
- }
- int m = (l + r) / 2;
- build(2 * v + 1, l, m);
- build(2 * v + 2, m, r);
- t[v] = max(t[2 * v + 1], t[2 * v + 2]);
- }
- void push(int v) {
- mod[2 * v + 1] += mod[v];
- mod[2 * v + 2] += mod[v];
- mod[v] = 0;
- }
- void update(int v, int l, int r, int askl, int askr, int val) {
- if (l >= askr || r <= askl) {
- return;
- }
- if (l >= askl && r <= askr) {
- mod[v] += val;
- return;
- }
- int m = (l + r) / 2;
- t[v] += val;
- push(v);
- update(2 * v + 1, l, m, askl, askr, val);
- update(2 * v + 2, m, r, askl, askr, val);
- }
- int get_ans(int v, int l, int r, int askl, int askr) {
- if (l >= askr || r <= askl) {
- return 0;
- }
- if (l >= askl && r <= askr) {
- return t[v] + mod[v];
- }
- push(v);
- int m = (l + r) / 2;
- return max(get_ans(2 * v + 1, l, m, askl, askr), get_ans(2 * v + 2, m, r, askl, askr));
- }
- signed main() {
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- cin >> n;
- a.resize(n);
- for (auto& k : a) cin >> k;
- t.resize(4 * n);
- build(0, 0, n);
- mod.assign(4 * n, 0);
- int q;
- cin >> q;
- char t;
- int l, r, val;
- while(q--) {
- cin >> t >> l >> r;
- l--;r--;
- if (t == 'm') {
- cout << get_ans(0, 0, n, l, r) << " ";
- } else {
- cin >> val;
- update(0, 0, n, l, r + 1, val);
- }
- }
- }
- /*
- 5
- 2 4 3 1 5
- 5
- m 1 3
- a 2 4 100
- m 1 3
- a 5 5 10
- m 1 5
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement