Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 1
- 2 3
- 4 5 6 7
- 8 9 10 11 12 13 14 15
- 1 2 3 4 5
- n
- a1 a2 a3 ... an
- m
- l1 r1
- l2 r2
- .
- .
- .
- ln rn
- #include <iostream>
- using namespace std;
- void build(int v, int L, int R) {
- if (L == R) {
- t[v] = a[L];
- return;
- }
- int mid = (L + R) / 2;
- build(v * 2, L, mid);
- build(v * 2 + 1, mid + 1, R);
- t[v] = max(t[v * 2], t[v * 2 + 1]);
- }
- int main() {
- cin >> n;
- for (int i = 1; i <= n; i++)
- cin >> a[i];
- build(1, 1, n);
- 1) sum
- 2) min
- дерево снизу и сверху
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement