Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- void build_tree(vector<int> &t, int v, int l, int r) {
- if (r-l == -1) {
- t[v] = a[l];
- return;
- }
- int m=(l+r)/2;
- build_tree(t, 2*v, l, m);
- build_tree(t, 2*v+1, m, r);
- t[v] = t[2*v] + t[2*v+1];
- }
- void change(vector<int> &t, int v, int n, int pos, int x) {
- if (l>pos || r<=pos)
- return;
- if (r-l == 1) {
- t[v] = x;
- return;
- }
- int m=(l+r)/2;
- change(t, 2*v, l, m, pos, x);
- change(t, 2*v+1, m, r, pos, x);
- t[v] = t[2*v] + t[2*v+1];
- }
- int get_sum(vector<int> &t, vector<int> &val, int v, int l, int r, int lt, int rt) {
- if (lt>=r|| l>=rt)
- return 0;
- if (lt<=l && r<=rt)
- return t[v];
- push(t,val, v, l, r);
- int m=(l+r)/2;
- int lsum=get_sum(t, 2*v, l, m, lt, rt);
- int rsum=get_sem(t, 2*v+1, m, r, lt, rt);
- t[v] = t[2*v] + t[2*v+1];
- return lsum + rsum;
- }
- void add_val(vector<int> &t, vector<int> &val, int v, int l, int r, int x) {
- t[v]=(r-l)*x;
- val[v]+=x;
- }
- void push (vector<int> &t, vector<int> &val, int v, int l, int r) {
- if (r-l == -1)
- return;
- int m=(l+r)/2;
- add_val(t, 2*v, l, m, val[v]);
- add_val(t, 2*v+1, m, r, val[v]);
- val[v] = 0;
- }
- void add_seg(vector<int> &t, vector<int> &val, int v, int l, int r, int lt, int rt, int x) {
- if (lt>=r || l>=rt)
- return;
- if (lt<=l && r<=rt) {
- add_val(t, val, v, l, r, x)
- return;
- }
- push(t, val, v, l, r);
- int m=(l+r)/2;
- add_seg(t, val, 2*v, v, l, m, lt, rt, x);
- add_seg(t, val, 2*v+1, v, m, r, lt, rt, x);
- t[v] = t[2*v] + t[2*v+1];
- }
- int main() {
- ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
- int N=0; cin >> N;
- vector<int> a(N), t1(N), t2(N), val(N);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement