# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
126176 |
2019-07-07T08:03:57 Z |
StevenH |
Wall (IOI14_wall) |
C++14 |
|
175 ms |
14096 KB |
#include "wall.h"
const int maxn = 100005;
struct Wall{
int max,min,val;
}wall[maxn*4];
int fh[maxn];
int max(int &x,int &y)
{
if(x>y)return x;
else return y;
}
int min(int &x,int &y)
{
if(x<y)return x;
else return y;
}
void push_up(int p)
{
if(p>1)
{
wall[p/2].max=max(wall[p].max,wall[p+1].max);
wall[p/2].min=min(wall[p].min,wall[p+1].min);
//cout<<p<<" "<<wall[p].max<<" "<<wall[p].min<<endl;
push_up(p/2);
return ;
}
return ;
}
void push_down(int p,int x,int y)
{
if(x<y)
{
wall[p*2]=wall[p];
wall[p*2+1]=wall[p];
int mid=(x+y)/2;
push_down(p*2,x,mid);
push_down(p*2+1,mid+1,y);
return ;
}
return ;
}
void add(int p,int x,int y,int tx,int ty,int h)
{
int mid=(x+y)/2;
//return ;
//cout<<p<<endl;
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;
if(p>1)push_up(p);
if(x<y)push_down(p,x,y);
}
else if(h<wall[p].min)return ;//高度小於區間最小
else
{
add(p*2,x,mid,tx,ty,h);
add(p*2+1,mid+1,y,tx,ty,h);
}
return ;
}
else
{
add(p*2,x,mid,tx,ty,h);
add(p*2+1,mid+1,y,tx,ty,h);
return ;
}
}
void rmv(int p,int x,int y,int tx,int ty,int h)
{
int mid=(x+y)/2;
//cout<<x<<" "<<y<<endl;
if(y<tx || ty<x)return ;
if(tx<=x && y<=ty) // xy在txty中
{
if(h<=wall[p].min) // 高度小於區間最低值 全部改
{
//cout<<x<<"-"<<y<<endl;
wall[p].max=h;
wall[p].min=h;
//cout<<p<<endl;
if(p>1)push_up(p);
if(x!=y)push_down(p,x,y);
}
else if(h>wall[p].max)return ;//高度大於區間最大 捨去
else
{
rmv(p*2,x,mid,tx,ty,h);
rmv(p*2+1,mid+1,y,tx,ty,h);
}
return ;
}
else
{
rmv(p*2,x,mid,tx,ty,h);
rmv(p*2+1,mid+1,y,tx,ty,h);
return ;
}
}
void find(int p,int x,int y)
{
if(wall[p].max==wall[p].min)
{
//cout<<x<<" "<<y<<endl;
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)
{
//cout<<"*";
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;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
4 ms |
504 KB |
Output is correct |
3 |
Incorrect |
4 ms |
376 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
175 ms |
14096 KB |
Output is correct |
3 |
Incorrect |
167 ms |
8316 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
252 KB |
Output is correct |
2 |
Correct |
4 ms |
376 KB |
Output is correct |
3 |
Incorrect |
4 ms |
376 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
420 KB |
Output is correct |
2 |
Correct |
4 ms |
504 KB |
Output is correct |
3 |
Incorrect |
4 ms |
376 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |