# |
제출 시각 |
아이디 |
문제 |
언어 |
결과 |
실행 시간 |
메모리 |
1006297 |
2024-06-23T17:02:13 Z |
jer033 |
벽 (IOI14_wall) |
C++17 |
|
78 ms |
10568 KB |
#include <bits/stdc++.h>
#include "wall.h"
using namespace std;
class SegTree{
public:
int left_index;
int right_index;
int lo_value;
int hi_value;
SegTree* left_child;
SegTree* right_child;
SegTree* parent;
SegTree(int l, int r, SegTree* magulang)
{
parent = magulang;
left_index = l;
right_index = r;
lo_value = 0;
hi_value = 0;
if (l==r)
{
left_child = nullptr;
right_child = nullptr;
}
else
{
int m = (l+r)/2;
left_child = new SegTree(l, m, this);
right_child = new SegTree(m+1, r, this);
}
}
SegTree(int n)
{
SegTree(0, n-1, nullptr);
}
void update_self()
{
if (hi_value < parent->lo_value)
{
lo_value = parent->lo_value;
hi_value = parent->lo_value;
}
else if (lo_value > parent->hi_value)
{
lo_value = parent->hi_value;
hi_value = parent->hi_value;
}
else
{
lo_value = max(lo_value, parent->lo_value);
hi_value = min(hi_value, parent->hi_value);
}
}
void update_children()
{
if (left_child!=nullptr)
{
left_child->update_self();
right_child->update_self();
}
}
void grab_new_info()
{
if (left_child!=nullptr)
{
lo_value = min(left_child->lo_value, right_child->lo_value);
hi_value = max(left_child->hi_value, right_child->hi_value);
}
if (parent!=nullptr)
parent->grab_new_info();
}
void modify_self(int typ, int h)
{
if (typ==1)
{
lo_value = h;
if (hi_value < h)
hi_value = h;
}
else
{
hi_value = h;
if (lo_value > h)
lo_value = h;
}
}
void builder(int typ, int l, int r, int h)
{
update_children();
int mid_index = (left_index+right_index)/2;
if ((l==left_index) and (r==right_index))
{
modify_self(typ, h);
grab_new_info();
}
else
{
if (l<=mid_index)
left_child->builder(typ, l, mid_index, h);
if (r>=(mid_index+1))
right_child->builder(typ, mid_index+1, r, h);
}
}
void answer(int finalHeight[])
{
if (left_index == right_index)
{
finalHeight[left_index] = lo_value;
}
else
{
update_children();
left_child->answer(finalHeight);
right_child->answer(finalHeight);
}
}
};
void buildWall(int n, int k, int op[], int left[], int right[], int height[], int finalHeight[])
{
SegTree* seg = new SegTree(n);
for (int oper = 0; oper<k; oper++)
{
int typ = op[oper];
int l = left[oper];
int r = right[oper];
int h = height[oper];
seg->builder(typ, l, r, h);
}
seg->answer(finalHeight);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 11 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
78 ms |
8024 KB |
Output is correct |
3 |
Runtime error |
41 ms |
10568 KB |
Execution killed with signal 11 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 11 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 11 |
4 |
Halted |
0 ms |
0 KB |
- |