#include "wall.h"
#include <iostream>
using namespace std;
int nn;
const int maxn = 2000005;
struct Wall{
int max,min,val;
}wall[maxn*4];
int fh[maxn];
void push_up(int p)
{
//cout<<p<<endl;
if(p>1)
{
int k=(p/2);
wall[k].max=max(wall[k*2].max,wall[k*2+1].max);
wall[k].min=min(wall[k*2].min,wall[k*2+1].min);
push_up(p/2);
}
}
void add(int p,int x,int y,int tx,int ty,int h)
{
int mid=(x+y)/2;
if(y<tx || ty<x)return ;
if(tx<=x && y<=ty) // xy在txty中
{
if(h>=wall[p].max) // 高度大於區間最高值 全部改
{
wall[p].max=h;
wall[p].min=h;
wall[p].val=h;
return ;
}
else if(h<wall[p].min)return ;//高度小於區間最小
}
if(wall[p].val>0)
{
wall[p*2].max=wall[p*2+1].max=wall[p].val;
wall[p*2].min=wall[p*2+1].min=wall[p].val;
wall[p*2].val=wall[p*2+1].val=wall[p].val;
wall[p].val=0;
}
add(p*2,x,mid,tx,ty,h);
add(p*2+1,mid+1,y,tx,ty,h);
wall[p].max=max(wall[p*2].max,wall[p*2+1].max);
wall[p].min=min(wall[p*2].min,wall[p*2+1].min);
return ;
}
void rmv(int p,int x,int y,int tx,int ty,int h)
{
int mid=(x+y)/2;
if(y<tx || ty<x)return ;
if(tx<=x && y<=ty) // xy在txty中
{
if(h<=wall[p].min) // 高度小於區間最低值 全部改
{
wall[p].max=h;
wall[p].min=h;
wall[p].val=h;
return ;
}
else if(h>wall[p].max)return ;//高度大於區間最大 捨去
}
if(wall[p].val>0)
{
wall[p*2].max=wall[p*2+1].max=wall[p].val;
wall[p*2].min=wall[p*2+1].min=wall[p].val;
wall[p*2].val=wall[p*2+1].val=wall[p].val;
wall[p].val=0;
}
rmv(p*2,x,mid,tx,ty,h);
rmv(p*2+1,mid+1,y,tx,ty,h);
wall[p].max=max(wall[p*2].max,wall[p*2+1].max);
wall[p].min=min(wall[p*2].min,wall[p*2+1].min);
return ;
}
void find(int p,int x,int y)
{
if(wall[p].max==wall[p].min)
{
for(int i=x;i<=y;i++)fh[i]=wall[p].min;
return ;
}
int mid=(x+y)/2;
find(p*2,x,mid);
find(p*2+1,mid+1,y);
return ;
}
void buildWall(int n, int k, int op[], int left[], int right[], int height[], int finalHeight[]){
for(int i=0;i<k;i++)
{
if(op[i]==1)add(1,0,n-1,left[i],right[i],height[i]);
if(op[i]==2)rmv(1,0,n-1,left[i],right[i],height[i]);
//find(1,0,n-1);
//for (int j=0;j<n;j++)printf("%d ", fh[j]);
//cout<<endl;
}
find(1,0,n-1);
for(int i=0;i<n;i++)finalHeight[i]=fh[i];
return;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
4 ms |
376 KB |
Output is correct |
3 |
Correct |
3 ms |
376 KB |
Output is correct |
4 |
Correct |
8 ms |
888 KB |
Output is correct |
5 |
Correct |
7 ms |
888 KB |
Output is correct |
6 |
Correct |
7 ms |
888 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
168 ms |
8312 KB |
Output is correct |
3 |
Correct |
182 ms |
4600 KB |
Output is correct |
4 |
Incorrect |
513 ms |
12172 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
4 ms |
376 KB |
Output is correct |
3 |
Correct |
4 ms |
376 KB |
Output is correct |
4 |
Correct |
9 ms |
888 KB |
Output is correct |
5 |
Correct |
7 ms |
888 KB |
Output is correct |
6 |
Correct |
7 ms |
888 KB |
Output is correct |
7 |
Correct |
2 ms |
452 KB |
Output is correct |
8 |
Correct |
168 ms |
8156 KB |
Output is correct |
9 |
Correct |
184 ms |
4560 KB |
Output is correct |
10 |
Incorrect |
522 ms |
12300 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
4 ms |
376 KB |
Output is correct |
3 |
Correct |
3 ms |
408 KB |
Output is correct |
4 |
Correct |
8 ms |
888 KB |
Output is correct |
5 |
Correct |
7 ms |
888 KB |
Output is correct |
6 |
Correct |
7 ms |
888 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
168 ms |
8184 KB |
Output is correct |
9 |
Correct |
181 ms |
4584 KB |
Output is correct |
10 |
Incorrect |
507 ms |
12336 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |