• API
• FAQ
• Tools
• Archive
SHARE
TWEET

# Untitled

a guest Dec 14th, 2019 88 in 324 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. #include <iostream>
2.
3. struct Node {
4.     Node() {
5.         x = -2147483647;
6.     }
7.
8.     int x;
9.
10.     Node(int x) {
11.         this->x = x;
12.     }
13. };
14.
15. Node max(Node p1, Node p2, int k) {
16.
17. }
18.
19. /*void push(Node *tree, int *mod, int v) {
20.     if (mod[v] == -1) return;
21.     mod[2 * v + 1] = mod[v];
22.     mod[2 * v + 2] = mod[v];
23.     tree[2 * v + 1].x = mod[v];
24.     tree[2 * v + 2].x = mod[v];
25.     mod[v] = -1;
26. }*/
27.
28. void modify(Node *tree, int *mod, int v, int L, int R, int i, int x, int k) {
29.     if (R - L == 1) {
30.         tree[v] = {x};
31.         return;
32.     }
33.     int M = (R + L) / 2;
34.     //push(tree, mod, v);
35.     if (i < M) {
36.         modify(tree, mod, 2 * v + 1, L, M, i, x, k);
37.     } else {
38.         modify(tree, mod, 2 * v + 2, M, R, i, x, k);
39.     }
40.     tree[v] = max(tree[2 * v + 1], tree[2 * v + 2], k);
41. }
42.
43. /*void add(Node *tree, int *mod, int v, int L, int R, int l, int r, int x) { // doesn't work
44.     if (L >= r || l >= R) return;
45.     if (l <= L && R <= r) {
46.         mod[v] = x;
47.         tree[v].x = x;
48.         return;
49.     }
50.     int M = (R + L) / 2;
51.     push(tree, mod, v);
52.     add(tree, mod, 2 * v + 1, L, M, l, r, x);
53.     add(tree, mod, 2 * v + 2, M, R, l, r, x);
54.     tree[v] = max(tree[2 * v + 1], tree[2 * v + 2]);
55. }*/
56.
57. Node maximum(Node *tree, int *mod, int v, int L, int R, int l, int r, int k) {
58.     if (l >= R || L >= r) return {-2147483647}; // neutral element
59.     if (l <= L && R <= r) return tree[v];
60.     int M = (R + L) / 2;
61.     //push(tree, mod, v);
62.     return max(maximum(tree, mod, 2 * v + 1, L, M, l, r, k), maximum(tree, mod, 2 * v + 2, M, R, l, r, k), k);
63. }
64.
65. /*int get(Node *tree, int *mod, int v, int L, int R, int i) {
66.     if (R - L == 1) return tree[v].x;
67.     int M = (R + L) / 2;
68.     push(tree, mod, v);
69.     if (i < M) {
70.         return get(tree, mod, 2 * v + 1, L, M, i);
71.     } else {
72.         return get(tree, mod, 2 * v + 2, M, R, i);
73.     }
74. }*/
75.
76. int main() {
77.     std::ios_base::sync_with_stdio(false);
78.     std::cin.tie(nullptr);
79.     int n;
80.     std::cin >> n;
81.     int arr[n];
82.     for (int i = 0; i < n; i++) std::cin >> arr[i];
83.     Node tree[n * 4];
84.     int mod[n * 4];
85.     for (int i = 0; i < n * 4; ++i) {
86.         mod[i] = -1;
87.     }
88.     for (int i = 0; i < n; i++) {
89.         modify(tree, mod, 0, 0, n, i, arr[i], 0);
90.     }
91.     int k;
92.     std::cin >> k;
93.     for (int i = 0; i < k; i++) {
94.         char c;
95.         int a, b;
96.
97.     }
98. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.

Top