Submission #558903

#TimeUsernameProblemLanguageResultExecution timeMemory
558903aryan12Wall (IOI14_wall)C++17
0 / 100
205 ms101960 KiB
#include "wall.h" #include <bits/stdc++.h> using namespace std; const int N = 2e6 + 5; int seg[N * 4]; vector<array<int, 3> > lazy(N * 4, {-1, 100001, -1}); 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) { if(lazy[pos][2] != -1) { lazy[pos * 2][0] = lazy[pos][0]; lazy[pos * 2 + 1][0] = lazy[pos][0]; lazy[pos * 2][1] = lazy[pos][1]; lazy[pos * 2 + 1][1] = lazy[pos][1]; lazy[pos * 2][2] = lazy[pos][2]; lazy[pos * 2 + 1][2] = lazy[pos][2]; } lazy[pos][2] = -1; // cout << "l = " << l << ", r = " << r << ", lazy[pos * 2] = {" << lazy[pos * 2][0] << ", " << lazy[pos * 2][1] << ", lazy[pos * 2 + 1] = {" << lazy[pos * 2 + 1][0] << ", " << lazy[pos * 2 + 1][1] << "}\n"; } else { if(seg[pos] < lazy[pos][0]) seg[pos] = lazy[pos][0]; if(seg[pos] > lazy[pos][1]) seg[pos] = lazy[pos][1]; return; } // cout << "l = " << l << ", r = " << r << ", lazy[pos * 2] = {" << lazy[pos * 2][0] << ", " << lazy[pos * 2][1] << ", lazy[pos * 2 + 1] = {" << lazy[pos * 2 + 1][0] << ", " << lazy[pos * 2 + 1][1] << "}\n"; } 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); lazy[pos][0] = max(lazy[pos][0], qvalue); lazy[pos][1] = max(lazy[pos][0], lazy[pos][1]); lazy[pos][2] = 1; } else //removing phase { seg[pos] = min(seg[pos], qvalue); lazy[pos][1] = min(lazy[pos][1], qvalue); lazy[pos][0] = min(lazy[pos][1], lazy[pos][0]); lazy[pos][2] = 2; } return; } int mid = (l + r) >> 1; 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][0] = max(lazy[pos][0], qvalue); lazy[pos][2] = 1; lazy[pos][1] = max(lazy[pos][1], lazy[pos][0]); // cout << lazy[pos * 2][0] << " " << lazy[pos * 2][1] << " " << lazy[pos * 2 + 1][0] << " " << lazy[pos * 2][1] << "\n"; } else { lazy[pos][1] = min(lazy[pos][1], qvalue); lazy[pos][2] = 2; lazy[pos][0] = min(lazy[pos][1], lazy[pos][0]); // cout << lazy[pos * 2][0] << " " << lazy[pos * 2][1] << " " << lazy[pos * 2 + 1][0] << " " << lazy[pos * 2][1] << "\n"; } return; } 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...