Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Pratiyush Mishra
- #include <bits/stdc++.h>
- #define ull unsigned long long int
- #define ll long long int
- #define LL_MAX 9223372036854775807
- #define pb push_back
- #define pf push_front
- #define mp make_pair
- #define popb pop_back
- #define vl vector<ll>
- #define pl pair<ll,ll>
- #define bs(v, x) binary_search(v.begin(), v.end(), x)
- #define mem1(a) memset(a, -1, sizeof(a))
- #define popf pop_front
- #define p0(x) cout << x << " "
- #define p1(x) cout << x << '\n'
- #define p2(x, y) cout << x << " " << y << '\n'
- #define p3(x, y, z) cout << x << " " << y << " " << z << '\n'
- #define printv(v) \
- for (ll i = 0; i < v.size(); ++i) \
- cout << v[i] << " "; \
- cout << '\n'
- #define pr1(x) cout << fixed << setprecision(15) << x << '\n'
- #define ordered_set tree<pair<ll, ll>, null_type, less<pair<ll, ll>>, rb_tree_tag, tree_order_statistics_node_update>
- // ordered_set s ; s.order_of_key(val) no. of elements strictly less than val
- // s.find_by_order(i) itertor to ith element (0 indexed)
- #define mod 1000000007
- #define mod1 998244353
- #define fio \
- ios_base::sync_with_stdio(false); \
- cin.tie(NULL)
- #define get(n) \
- ll n; \
- cin >> n
- #define getvec(v, n) \
- vector<ll> v(n); \
- for (ll i = 0; i < n; i++) \
- cin >> v[i];
- #define getstr(s) \
- string s; \
- cin >> s
- #define all(x) x.begin(), x.end()
- #define countBits(x) __builtin_popcount(x)
- using namespace std;
- // Solution to the problem: https://codeforces.com/edu/course/2/lesson/5/1/practice/contest/279634/problem/A
- ll n, q;
- ll l, r, pos, val;
- const ll M = 100000 * 4 + 50;
- ll tree[M], lazy[M], v[M];
- void build(int tl, int tr, ll node)
- {
- if (tl == tr)
- {
- tree[node] = v[tl];
- return;
- }
- int tm = (tl + tr) / 2;
- build(tl, tm, 2 * node);
- build(tm + 1, tr, 2 * node + 1);
- tree[node] = (tree[2 * node] + tree[2 * node + 1]);
- }
- void apply(int tl, int tr, ll node, ll val)
- {
- tree[node] += (val * (tr - tl + 1));
- if (tl != tr)
- lazy[node] += val;
- }
- void passdown(int tl, int tr, ll node)
- {
- int tm = (tl + tr) / 2;
- apply(tl, tm, 2 * node, lazy[node]);
- apply(tm + 1, tr, 2 * node + 1, lazy[node]);
- lazy[node] = 0;
- }
- void update(int tl, int tr, ll node)
- {
- if (tl > r || tr < l)
- return;
- if (tl >= l && tr <= r)
- {
- apply(tl, tr, node, val);
- return;
- }
- passdown(tl, tr, node);
- int tm = (tl + tr) / 2;
- update(tl, tm, 2 * node);
- update(tm + 1, tr, 2 * node + 1);
- tree[node] = (tree[2 * node] + tree[2 * node + 1]);
- }
- ll query(int tl, int tr, int node)
- {
- if (tl > r || tr < l)
- return 0;
- if (tl >= l && tr <= r)
- return tree[node];
- passdown(tl, tr, node);
- int tm = (tl + tr) / 2;
- ll ans = query(tl, tm, 2 * node) + query(tm + 1, tr, 2 * node + 1);
- return ans;
- }
- void mainSolve()
- {
- cin >> n >> q;
- for (int i = 1; i <= n; i++)
- v[i] = 0;
- build(1, n, 1);
- while (q--)
- {
- int t;
- cin >> t;
- if (t == 1)
- {
- cin >> l >> r >> val;
- ++l;
- update(1, n, 1);
- }
- else
- {
- cin >> l;
- ++l;
- r = l;
- cout << query(1, n, 1) << endl;
- }
- }
- }
- int main()
- {
- fio;
- #ifndef ONLINE_JUDGE
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- #endif
- //get(t);
- ll t = 1;
- while (t--)
- {
- mainSolve();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement