Submission #321609

#TimeUsernameProblemLanguageResultExecution timeMemory
321609nikatamlianiWall (IOI14_wall)C++14
100 / 100
877 ms99692 KiB
#include <bits/stdc++.h> using namespace std; const int oo = 1e9 + 6; struct node { int maxi, mini; node() { mini = oo; maxi = 0; } }; vector<node> tree; void apply(int p, int L, int R) { node& me = tree[p]; me.mini = max(min(me.mini, R), L); me.maxi = max(min(me.maxi, R), L); } void push(int l, int r, int p) { node& me = tree[p]; if(l < r) { apply(p << 1, me.maxi, me.mini); apply(p << 1 | 1, me.maxi, me.mini); } me.mini = oo; me.maxi = 0; } void update(int l, int r, int L, int R, int val_L, int val_R, int p) { if(l > R || L > r) return; if(L <= l && R >= r) { apply(p, val_L, val_R); } else { push(l, r, p); int m = l + r >> 1; update(l, m, L, R, val_L, val_R, p << 1); update(m + 1, r, L, R, val_L, val_R, p << 1 | 1); } } void traverse(int l, int r, int p, int finalHeight[]) { if(l == r) { finalHeight[l - 1] = tree[p].maxi; } else { push(l, r, p); int m = l + r >> 1; traverse(l, m, p << 1, finalHeight); traverse(m + 1, r, p << 1 | 1, finalHeight); } } void buildWall(int n, int k, int op[], int left[], int right[], int height[], int finalHeight[]) { tree.resize(4 * n + 1); for(int i = 0; i < k; ++i) { if(op[i] == 1) { update(1, n, left[i] + 1, right[i] + 1, height[i], oo, 1); } else { update(1, n, left[i] + 1, right[i] + 1, -oo, height[i], 1); } } traverse(1, n, 1, finalHeight); } // int main() { // int n, k; // cin >> n >> k; // int op[k], left[k], right[k], height[k], finalHeight[k]; // memset(finalHeight, -1, sizeof finalHeight); // for(int i = 0; i < k; ++i) { // cin >> op[i] >> left[i] >> right[i] >> height[i]; // } // buildWall(n, k, op, left, right, height, finalHeight); // for(int i = 0; i < n; ++i) { // cout << finalHeight[i] << ' '; // } // }

Compilation message (stderr)

wall.cpp: In function 'void update(int, int, int, int, int, int, int)':
wall.cpp:32:19: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   32 |         int m = l + r >> 1;
      |                 ~~^~~
wall.cpp: In function 'void traverse(int, int, int, int*)':
wall.cpp:42:19: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   42 |         int m = l + r >> 1;
      |                 ~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...