This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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)
{
lazy[pos * 2][0] = max(lazy[pos * 2][0], lazy[pos][0]);
lazy[pos * 2][1] = min(lazy[pos * 2][1], lazy[pos][1]);
lazy[pos * 2 + 1][0] = max(lazy[pos * 2 + 1][0], lazy[pos][0]);
lazy[pos * 2 + 1][1] = min(lazy[pos * 2 + 1][1], lazy[pos][1]);
if(lazy[pos][2] != -1)
{
lazy[pos * 2][2] = lazy[pos][2];
lazy[pos * 2 + 1][2] = lazy[pos][2];
}
lazy[pos] = {-1, 100001, -1};
}
else
{
if(seg[pos] < lazy[pos][0]) seg[pos] = lazy[pos][0];
if(seg[pos] > lazy[pos][1]) seg[pos] = lazy[pos][1];
lazy[pos] = {-1, 100001, -1};
return;
}
if(lazy[pos * 2][0] > lazy[pos * 2][1])
{
if(lazy[pos * 2][2] == 1)
{
lazy[pos * 2][1] = lazy[pos * 2][0];
}
else
{
lazy[pos * 2][0] = lazy[pos * 2][1];
}
// lazy[pos * 2][2] = -1;
}
if(lazy[pos * 2 + 1][0] > lazy[pos * 2 + 1][1])
{
if(lazy[pos * 2 + 1][2] == 1)
{
lazy[pos * 2 + 1][1] = lazy[pos * 2 + 1][0];
}
else
{
lazy[pos * 2 + 1][0] = lazy[pos * 2 + 1][1];
}
// lazy[pos * 2 + 1][2] = -1;
}
}
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;
}
int mid = (l + r) >> 1;
if(qleft <= l && r <= qright)
{
UpdateLazy(l, mid, pos * 2);
UpdateLazy(mid + 1, r, pos * 2 + 1);
// 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][0] = max(lazy[pos * 2][0], qvalue);
lazy[pos * 2 + 1][0] = max(lazy[pos * 2 + 1][0], qvalue);
lazy[pos * 2][2] = 1;
lazy[pos * 2 + 1][2] = 1;
}
else
{
lazy[pos * 2][1] = min(lazy[pos * 2][1], qvalue);
lazy[pos * 2 + 1][1] = min(lazy[pos * 2 + 1][1], qvalue);
lazy[pos * 2][2] = 2;
lazy[pos * 2 + 1][2] = 2;
}
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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |