제출 #947580

#제출 시각아이디문제언어결과실행 시간메모리
947580steveonalex벽 (IOI14_wall)C++11
24 / 100
393 ms13444 KiB
#include <bits/stdc++.h> #include "wall.h" using namespace std; typedef long long ll; typedef unsigned long long ull; #define MASK(i) (1ULL << (i)) #define GETBIT(mask, i) (((mask) >> (i)) & 1) #define ALL(v) (v).begin(), (v).end() ll max(ll a, ll b){return (a > b) ? a : b;} ll min(ll a, ll b){return (a < b) ? a : b;} ll LASTBIT(ll mask){return (mask) & (-mask);} int pop_cnt(ll mask){return __builtin_popcountll(mask);} int ctz(ll mask){return __builtin_ctzll(mask);} int logOf(ll mask){return 63 - __builtin_clzll(mask);} mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count()); ll rngesus(ll l, ll r){return l + (ull) rng() % (r - l + 1);} template <class T1, class T2> bool maximize(T1 &a, T2 b){ if (a < b) {a = b; return true;} return false; } template <class T1, class T2> bool minimize(T1 &a, T2 b){ if (a > b) {a = b; return true;} return false; } template <class T> void printArr(T& container, string separator = " ", string finish = "\n", ostream &out = cout){ for(auto item: container) out << item << separator; out << finish; } template <class T> void remove_dup(vector<T> &a){ sort(ALL(a)); a.resize(unique(ALL(a)) - a.begin()); } struct SegmentTree{ struct Node{ int time, op, h; Node(int _time = -1, int _op = -1, int _h = -1){ time = _time, op = _op, h = _h; } }; int n; vector<pair<Node, Node>> a; SegmentTree(int _n){ n = _n; a.resize(n * 2 + 2); } pair<Node, Node> combine(pair<Node, Node> a, pair<Node, Node> b){ Node sigma_duck[] = {a.first, a.second, b.first, b.second}; sort(sigma_duck, sigma_duck + 4, [] (Node a, Node b){return a.time < b.time;}); pair<Node, Node> ans; for(Node i: sigma_duck){ if (i.time == -1) continue; if (i.op == 1){ if (maximize(ans.first.h, i.h)) { ans.first = i; if (ans.second.time != -1) maximize(ans.second.h, i.h); } } else{ if (ans.second.h == -1 || minimize(ans.second.h, i.h)) { ans.second = i; if (ans.first.time != -1) minimize(ans.first.h, i.h); } } } return ans; } void update(int l, int r, int t, int op, int h){ pair<Node, Node> cur; if (op == 1) cur.first = Node(t, op, h); else cur.second = Node(t, op, h); l += n; r += n + 1; while(l < r){ if (l & 1) { a[l] = combine(a[l], cur); l++; } if (r & 1){ r--; a[r] = combine(a[r], cur); } l >>= 1; r >>= 1; } } int get(int i, int h){ i += n; vector<Node> sigma; while(i > 0){ if (a[i].first.time != -1) sigma.push_back(a[i].first); if (a[i].second.time != -1) sigma.push_back(a[i].second); i >>= 1; } sort(ALL(sigma), [] (Node a, Node b){return a.time < b.time;}); for(auto i: sigma){ if (i.op == 1){ maximize(h, i.h); } else{ minimize(h, i.h); } } return h; } }; void buildWall(int n, int k, int op[], int left[], int right[],int height[], int finalHeight[]){ SegmentTree st(n); for(int i = 0; i<k; ++i) st.update(left[i] + 1, right[i] + 1, i, op[i], height[i]); for(int i= 0; i<n; ++i) finalHeight[i] = st.get(i + 1, 0); } // int main(void){ // ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); // return 0; // }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...