Submission #519071

#TimeUsernameProblemLanguageResultExecution timeMemory
519071tabrWall (IOI14_wall)C++17
0 / 100
125 ms13888 KiB
#include <bits/stdc++.h> using namespace std; #ifdef tabr #include "library/debug.cpp" #else #define debug(...) #endif #ifndef tabr #include "wall.h" #endif const int inf = (int) 1e9; struct segtree { using T = int; using F = pair<int, int>; int n; int size; int log_size; vector<T> node; vector<F> lazy; T e() { return 0; } F id() { return make_pair(-inf, inf); } T op(T a, T b) { return min(a, b); } T mapping(F f, T x) { x = max(x, f.first); x = min(x, f.first); return x; } F composition(F f, F g) { if (f.first == f.second) { return f; } if (g.first == g.second) { if (g.first < f.first) { return make_pair(f.first, f.first); } if (f.second < g.second) { return make_pair(f.second, f.second); } return g; } return make_pair(max(f.first, g.first), min(f.second, g.second)); } segtree() : segtree(0) {} segtree(int _n) { build(vector<T>(_n, e())); } segtree(const vector<T>& v) { build(v); } void build(const vector<T>& v) { n = (int) v.size(); if (n <= 1) { log_size = 0; } else { log_size = 32 - __builtin_clz(n - 1); } size = 1 << log_size; node.resize(2 * size, e()); lazy.resize(size, id()); for (int i = 0; i < n; i++) { node[i + size] = v[i]; } for (int i = size - 1; i > 0; i--) { pull(i); } } void push(int x) { node[2 * x] = mapping(lazy[x], node[2 * x]); node[2 * x + 1] = mapping(lazy[x], node[2 * x + 1]); if (2 * x < size) { lazy[2 * x] = composition(lazy[x], lazy[2 * x]); lazy[2 * x + 1] = composition(lazy[x], lazy[2 * x + 1]); } lazy[x] = id(); } void pull(int x) { node[x] = op(node[2 * x], node[2 * x + 1]); } void set(int p, T v) { assert(0 <= p && p < n); p += size; for (int i = log_size; i >= 1; i--) { push(p >> i); } node[p] = v; for (int i = 1; i <= log_size; i++) { pull(p >> i); } } T get(int p) { assert(0 <= p && p < n); p += size; for (int i = log_size; i >= 1; i--) { push(p >> i); } return node[p]; } T get(int l, int r) { assert(0 <= l && l <= r && r <= n); l += size; r += size; for (int i = log_size; i >= 1; i--) { if (((l >> i) << i) != l) { push(l >> i); } if (((r >> i) << i) != r) { push((r - 1) >> i); } } T vl = e(); T vr = e(); while (l < r) { if (l & 1) { vl = op(vl, node[l++]); } if (r & 1) { vr = op(node[--r], vr); } l >>= 1; r >>= 1; } return op(vl, vr); } void apply(int p, F f) { assert(0 <= p && p < n); p += size; for (int i = log_size; i >= 1; i--) { push(p >> i); } node[p] = mapping(f, node[p]); for (int i = 1; i <= log_size; i++) { pull(p >> i); } } void apply(int l, int r, F f) { assert(0 <= l && l <= r && r <= n); l += size; r += size; for (int i = log_size; i >= 1; i--) { if (((l >> i) << i) != l) { push(l >> i); } if (((r >> i) << i) != r) { push((r - 1) >> i); } } int ll = l; int rr = r; while (l < r) { if (l & 1) { node[l] = mapping(f, node[l]); if (l < size) { lazy[l] = composition(f, lazy[l]); } l++; } if (r & 1) { r--; node[r] = mapping(f, node[r]); if (l < size) { lazy[r] = composition(f, lazy[r]); } } l >>= 1; r >>= 1; } l = ll; r = rr; for (int i = 1; i <= log_size; i++) { if (((l >> i) << i) != l) { pull(l >> i); } if (((r >> i) << i) != r) { pull((r - 1) >> i); } } } }; void buildWall(int n, int k, int op[], int l[], int r[], int h[], int res[]) { segtree seg(n); for (int i = 0; i < k; i++) { if (op[i] == 1) { seg.apply(l[i], r[i] + 1, make_pair(h[i], inf)); } else { seg.apply(l[i], r[i] + 1, make_pair(-inf, h[i])); } } for (int i = 0; i < n; i++) { res[i] = seg.get(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...