Submission #697828

#TimeUsernameProblemLanguageResultExecution timeMemory
697828TheSahibWall (IOI14_wall)C++14
0 / 100
227 ms8088 KiB
#include <bits/stdc++.h> #define ll long long #define i128 __int128_t #define pii pair<int, int> #define oo 1e9 using namespace std; int N; vector<pii> tree; vector<bool> lazy; void push(int node, int l, int r){ if(!lazy[node]) return; if(l != r){ lazy[node * 2 + 1] = lazy[node * 2 + 2] = 1; tree[node * 2 + 1].second = min(tree[node * 2 + 1].second, tree[node].second); tree[node * 2 + 1].first = min(tree[node * 2 + 1].first, tree[node * 2 + 1].second); tree[node * 2 + 2].second = min(tree[node * 2 + 2].second, tree[node].second); tree[node * 2 + 2].first = min(tree[node * 2 + 2].first, tree[node * 2 + 2].second); } lazy[node] = 0; } void update(int node, int l, int r, int ul, int ur, pii val){ push(node, l, r); if(ur < l || r < ul){ return; } if(ul <= l && r <= ur){ if(val.first != -oo){ tree[node].first = max(tree[node].first, val.first); tree[node].second = max(tree[node].second, tree[node].first); lazy[node] = 1; } if(val.second != oo){ tree[node].second = min(tree[node].second, val.second); tree[node].first = min(tree[node].second, tree[node].first); lazy[node] = 1; } push(node, l, r); return; } int mid = (l + r) / 2; update(node * 2 + 1, l, mid, ul, ur, val); update(node * 2 + 2, mid + 1, r, ul, ur, val); tree[node] = {min(tree[node * 2 + 1].first, tree[node * 2 + 2].first), max(tree[node * 2 + 1].second, tree[node * 2 + 2].second)}; } void ask(int node, int l, int r, int pos, int &ans){ push(node, l, r); ans = max(tree[node].first, ans); ans = min(tree[node].second, ans); if(l == r){ return; } int mid = (l + r) / 2; if(pos <= mid){ ask(node * 2 + 1, l, mid, pos, ans); } else{ ask(node * 2 + 2, mid + 1, r, pos, ans); } } void buildWall(int n, int k, int op[], int left[], int right[], int height[], int finalHeight[]){ N = n; tree.resize(N * 4, {0, oo}); lazy.resize(N * 4, 0); for (int i = 0; i < k; i++) { update(0, 0, N - 1, left[i], right[i], {(op[i] == 1) ? height[i] : -oo, (op[i] == 2) ? height[i] : oo}); } for (int i = 0; i < N; i++) { int a = 0; ask(0, 0, N - 1, i, a); finalHeight[i] = a; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...