#include "wall.h"
//#include "grader.cpp"
#include <vector>
#include <iostream>
using namespace std;
const int MAXN = 1e5 + 5;
struct Range
{
int l, r;
Range(){}
Range(int l, int r)
{
this->l = l;
this->r = r;
}
int f(int x)
{
if(x<=l) return l;
if(x>=r) return r;
return x;
}
};
Range Merge(Range first, Range second)
{
if(second.l>=first.r) return Range(second.l, second.l);
if(second.r<=first.l) return Range(second.r, second.r);
if(second.l<=first.l && first.r<=second.r) return Range(first.l, first.r);
if(first.l<=second.l && second.r<=first.r) return Range(second.l, second.r);
if(first.l<=second.l && first.r<=second.r && second.l<=first.r) return Range(second.l, first.r);
if(second.l<=first.l && second.r<=first.r && first.l<=second.r) return Range(first.l, second.r);
}
struct SegmentTree
{
Range val;
int l, r;
SegmentTree *L, *R;
SegmentTree(){}
SegmentTree(int l, int r)
{
this->val = Range(0, MAXN);
this->l = l;
this->r = r;
this->L = nullptr;
this->R = nullptr;
}
void build()
{
if(l==r) return;
L = new SegmentTree(l, (l+r)/2);
R = new SegmentTree((l+r)/2+1, r);
L->build();
R->build();
}
void rem(int q)
{
if(l==r && q==l)
{
val = Range(0, MAXN);
return;
}
if(q<l || q>r) return;
L->rem(q);
R->rem(q);
val = Merge(L->val, R->val);
}
void add(int q, Range newVal)
{
if(l==r && q==l)
{
val = newVal;
return;
}
if(q<l || q>r) return;
L->add(q, newVal);
R->add(q, newVal);
val = Merge(L->val, R->val);
}
void reset()
{
//if(val==Range(0, MAXN)) return;
val = Range(0, MAXN);
if(L!=nullptr)
{
L->reset();
R->reset();
}
}
};
vector <int> toRemove[MAXN], toAdd[MAXN];
void buildWall(int n, int k, int op[], int left[], int right[], int height[], int finalHeight[])
{
SegmentTree *T = new SegmentTree(0, k-1);
T->build();
for(int i = 0;i<k;i++)
{
toAdd[ left[i] ].push_back(i);
toRemove[ right[i] ].push_back(i);
}
for(int ind = 0;ind<n;ind++)
{
if(ind!=0)
{
for(int i: toRemove[ind-1])
T->rem(i);
}
for(int i: toAdd[ind])
{
if(op[i]==1) T->add(i, Range(height[i], MAXN));//ans = Merge(ans, Range(height[i], MAXN));
else T->add(i, Range(0, height[i]));//ans = Merge(ans, Range(0, height[i]));
}
finalHeight[ind] = T->val.f(0);
}
}
Compilation message
wall.cpp: In function 'Range Merge(Range, Range)':
wall.cpp:38:1: warning: control reaches end of non-void function [-Wreturn-type]
38 | }
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
4992 KB |
Output is correct |
2 |
Correct |
7 ms |
5632 KB |
Output is correct |
3 |
Correct |
6 ms |
5248 KB |
Output is correct |
4 |
Correct |
11 ms |
5888 KB |
Output is correct |
5 |
Correct |
10 ms |
5888 KB |
Output is correct |
6 |
Correct |
11 ms |
5888 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4992 KB |
Output is correct |
2 |
Correct |
371 ms |
63904 KB |
Output is correct |
3 |
Correct |
473 ms |
31132 KB |
Output is correct |
4 |
Correct |
1476 ms |
73292 KB |
Output is correct |
5 |
Correct |
561 ms |
71416 KB |
Output is correct |
6 |
Correct |
527 ms |
71416 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
4992 KB |
Output is correct |
2 |
Correct |
7 ms |
5632 KB |
Output is correct |
3 |
Correct |
6 ms |
5248 KB |
Output is correct |
4 |
Correct |
11 ms |
5888 KB |
Output is correct |
5 |
Correct |
10 ms |
5888 KB |
Output is correct |
6 |
Correct |
10 ms |
5888 KB |
Output is correct |
7 |
Correct |
4 ms |
4992 KB |
Output is correct |
8 |
Correct |
377 ms |
64012 KB |
Output is correct |
9 |
Correct |
457 ms |
31548 KB |
Output is correct |
10 |
Correct |
1436 ms |
73172 KB |
Output is correct |
11 |
Correct |
563 ms |
71416 KB |
Output is correct |
12 |
Correct |
525 ms |
71416 KB |
Output is correct |
13 |
Correct |
4 ms |
4992 KB |
Output is correct |
14 |
Correct |
363 ms |
67468 KB |
Output is correct |
15 |
Correct |
53 ms |
9976 KB |
Output is correct |
16 |
Correct |
1465 ms |
73812 KB |
Output is correct |
17 |
Correct |
561 ms |
71308 KB |
Output is correct |
18 |
Correct |
568 ms |
71032 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
4992 KB |
Output is correct |
2 |
Correct |
8 ms |
5632 KB |
Output is correct |
3 |
Correct |
6 ms |
5248 KB |
Output is correct |
4 |
Correct |
12 ms |
5888 KB |
Output is correct |
5 |
Correct |
10 ms |
5888 KB |
Output is correct |
6 |
Correct |
10 ms |
5888 KB |
Output is correct |
7 |
Correct |
4 ms |
4992 KB |
Output is correct |
8 |
Correct |
364 ms |
64012 KB |
Output is correct |
9 |
Correct |
466 ms |
31496 KB |
Output is correct |
10 |
Correct |
1404 ms |
73320 KB |
Output is correct |
11 |
Correct |
547 ms |
71492 KB |
Output is correct |
12 |
Correct |
532 ms |
71416 KB |
Output is correct |
13 |
Correct |
5 ms |
4992 KB |
Output is correct |
14 |
Correct |
429 ms |
67772 KB |
Output is correct |
15 |
Correct |
53 ms |
9976 KB |
Output is correct |
16 |
Correct |
1391 ms |
73848 KB |
Output is correct |
17 |
Correct |
567 ms |
71288 KB |
Output is correct |
18 |
Correct |
577 ms |
71032 KB |
Output is correct |
19 |
Runtime error |
350 ms |
124408 KB |
Execution killed with signal 11 |
20 |
Halted |
0 ms |
0 KB |
- |