Submission #558875

#TimeUsernameProblemLanguageResultExecution timeMemory
558875aryan12Wall (IOI14_wall)C++17
24 / 100
464 ms82764 KiB
#include "wall.h" #include <bits/stdc++.h> using namespace std; const int N = 2e6 + 5; int seg[N * 4]; vector<pair<int, int> > lazy(N * 4, {-1, 100001}); void UpdateLazy(int l, int r, int pos) { // if(l == 0 && r == 0 && lazy[pos].size() != 0) // { // cout << "\n\n\n\n\n\n\n\n\n\n\n"; // cout << "lazy[pos].size() = " << lazy[pos].size() << "\n"; // cout << "\n\n\n\n\n\n\n\n\n\n\n"; // } if(l != r) { lazy[pos * 2].first = max(lazy[pos * 2].first, lazy[pos].first); lazy[pos * 2].second = min(lazy[pos * 2].second, lazy[pos].second); lazy[pos * 2 + 1].first = max(lazy[pos * 2 + 1].first, lazy[pos].first); lazy[pos * 2 + 1].second = min(lazy[pos * 2 + 1].second, lazy[pos].second); lazy[pos] = {-1, 100001}; } else { if(seg[pos] < lazy[pos].first) seg[pos] = lazy[pos].first; if(seg[pos] > lazy[pos].second) seg[pos] = lazy[pos].second; lazy[pos] = {-1, 100001}; } } int Query(int l, int r, int pos, int qpos) { // cout << "l = " << l << ", r = " << r << ", pos = " << pos << ", qpos = " << qpos << "\n"; UpdateLazy(l, r, pos); if(l == r) { return seg[pos]; } int mid = (l + r) >> 1; if(qpos <= mid) { return Query(l, mid, pos * 2, qpos); } return Query(mid + 1, r, pos * 2 + 1, qpos); } void Update(int l, int r, int pos, int qoperation, int qleft, int qright, int qvalue) { UpdateLazy(l, r, pos); if(qleft > r || l > qright) { // cout << "Update: (" << l << ", " << r << "), query range(" << qleft << ", " << qright << ", query operation and value: (" << qoperation << ", " << qvalue << ")\n"; // cout << "no intersection\n"; return; } if(l == r) { // cout << "Update: (" << l << ", " << r << "), query range(" << qleft << ", " << qright << ", query operation and value: (" << qoperation << ", " << qvalue << ")\n"; // cout << "full intersection (point)\n"; if(qoperation == 1) //adding phase { seg[pos] = max(seg[pos], qvalue); } else //removing phase { seg[pos] = min(seg[pos], qvalue); } return; } if(qleft <= l && r <= qright) { // cout << "Update: (" << l << ", " << r << "), query range(" << qleft << ", " << qright << ", query operation and value: (" << qoperation << ", " << qvalue << ")\n"; // cout << "full intersection (range)\n"; if(qoperation == 1) // adding phase { lazy[pos * 2].first = max(lazy[pos * 2].first, qvalue); lazy[pos * 2 + 1].first = max(lazy[pos * 2 + 1].first, qvalue); } else { lazy[pos * 2].second = min(lazy[pos * 2].second, qvalue); lazy[pos * 2 + 1].second = min(lazy[pos * 2 + 1].second, qvalue); } return; } int mid = (l + r) >> 1; Update(l, mid, pos * 2, qoperation, qleft, qright, qvalue); Update(mid + 1, r, pos * 2 + 1, qoperation, qleft, qright, qvalue); // cout << "Update: (" << l << ", " << r << "), query range(" << qleft << ", " << qright << ", query operation and value: (" << qoperation << ", " << qvalue << ")\n"; // cout << "partial intersection\n"; } void buildWall(int n, int k, int op[], int left[], int right[], int height[], int finalHeight[]) { for(int i = 0; i < k; i++) { Update(0, n - 1, 1, op[i], left[i], right[i], height[i]); // cout << "QUERYING\n"; // for(int j = 0; j < n; j++) // { // cout << Query(0, n - 1, 1, j) << "\n"; // } // cout << "\n\n\n\n\n"; } for(int i = 0; i < n; i++) { finalHeight[i] = Query(0, n - 1, 1, 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...