Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- struct node
- {
- int maximo, minimo;
- int sum, mul;
- void join(node l, node r)
- {
- maximo = max(l.maximo, r.maximo);
- minimo = min(l.minimo, r.minimo);
- sum = l.sum + r.sum;
- mul = l.mul * r.mul;
- }
- };
- node T[4 * 100000];
- int A[100000];
- void init(int b, int e, int nodo)
- {
- int mid = (b+e)/2, L = 2 * nodo + 1, R = L + 1;
- if (b == e) T[nodo].maximo = T[nodo].minimo = T[nodo].sum = T[nodo].mul = A[b]; // o como quieras inicializar el nodo, podrias hacer una funcion
- else
- {
- init(b, mid, L);
- init(mid+1, e, R);
- T[nodo].join(T[L], T[R]);
- }
- }
- void update(int b, int e, int nodo, int pos, int val)
- {
- int mid = (b+e)/2, L = 2 * nodo + 1, R = L + 1;
- if (b == e) T[nodo].maximo = T[nodo].minimo = T[nodo].sum = T[nodo].mul = val;
- else
- {
- if (pos <= mid) update(b, mid, L, pos, val);
- else update(mid+1, e, R, pos, val);
- T[nodo].join(T[L], T[R]);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement