Submission #540333

#TimeUsernameProblemLanguageResultExecution timeMemory
540333schiftyfive4Wall (IOI14_wall)C++14
100 / 100
1405 ms149208 KiB
#include <bits/stdc++.h> #include "wall.h" using namespace std; const int inf = 2e9; template<class T> struct SegTree { int n; vector<T> t, tag; SegTree(int _) { n = _; t.resize(4 * n, {0, 0}); tag.resize(4 * n, {0, inf}); } void apply(T &x, T &val) { if (x.first <= val.first && val.second <= x.second) { x = val; } else if (x.second <= val.first) { x.first = val.first; x.second = val.first; } else if (x.first >= val.second) { x.first = val.second; x.second = val.second; } else if (x.first <= val.first && val.first <= x.second && x.second <= val.second) { x.first = val.first; } else if (val.first <= x.first && x.first <= val.second && val.second <= x.second) { x.second = val.second; } } T join(T &y, T &z) { T res; res.first = min(y.first, z.first); res.second = max(y.second, z.second); return res; } void push(int v) { apply(t[2 * v], tag[v]); apply(tag[2 * v], tag[v]); apply(t[2 * v + 1], tag[v]); apply(tag[2 * v + 1], tag[v]); tag[v] = {0, inf}; } void modify(int v, int l, int r, int a, int b, T val) { if (l > b || r < a) { return; } if (a <= l && r <= b) { // cout << "(l, r) = " << l << ' ' << r << '\n'; // cout << "val: " << val.first << ' ' << val.second << '\n'; // cout << "before: " << t[v].first << ' ' << t[v].second << '\n'; apply(t[v], val); apply(tag[v], val); // cout << "after: " << t[v].first << ' ' << t[v].second << '\n'; // cout << tag[v].first << ' ' << tag[v].second << '\n'; // cout << '\n'; return; } push(v); int m = (l + r) / 2; modify(2 * v, l, m, a, b, val); modify(2 * v + 1, m + 1, r, a, b, val); t[v] = join(t[2 * v], t[2 * v + 1]); } int query(int v, int l, int r, int pos) { // cout << l << ' ' << r << ' ' << t[v].first << ' ' << t[v].second << '\n'; if (l == r) { assert(t[v].first == t[v].second); return t[v].first; } push(v); int m = (l + r) / 2; if (pos <= m) { return query(2 * v, l, m, pos); } return query(2 * v + 1, m + 1, r, pos); } void modify(int a, int b, T val) { modify(1, 0, n - 1, a, b, val); } int query(int pos) { return query(1, 0, n - 1, pos); } }; void buildWall(int n, int k, int op[], int left[], int right[], int height[], int finalHeight[]){ // cout << '\n'; SegTree<pair<int, int>> t(n); for (int i = 0; i < k; i++) { if (op[i] == 1) { t.modify(left[i], right[i], {height[i], inf}); } else { t.modify(left[i], right[i], {0, height[i]}); } } // cout << "\nbruh\n"; // for (int j = 0; j < n; j++) { // cout << t.query(j) << ' '; // } // cout << '\n'; for (int i = 0; i < n; i++) { finalHeight[i] = t.query(i); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...