답안 #779089

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
779089 2023-07-11T07:39:49 Z Trumling 벽 (IOI14_wall) C++14
0 / 100
150 ms 8036 KB
#include "wall.h"
#include <bits/stdc++.h>
using namespace std; 
 
typedef long long ll;
#define pb push_back
#define F first
#define S second
#define enter cout<<'\n';
#define INF 99999999999999999
#define MOD 1000000007
#define all(x) x.begin(),x.end()
 
ll laz[8000000];
ll seg[8000000];
ll ans[3000000];
 
void lazy(int idx)
{
  if(laz[idx]==INF)
  return ;

  if(laz[idx]<0)
  {
    if(laz[idx*2]==INF)
    {
      laz[idx*2]=laz[idx];
      seg[idx*2]=-laz[idx]-1;
    }
    else
    if(((laz[idx*2]<0)?-laz[idx*2]:laz[idx*2])>-laz[idx])
    {
      laz[idx*2]=laz[idx];
      seg[idx*2]=-laz[idx]-1;
    }
 
    if(laz[idx*2+1]==INF)
    {
      laz[idx*2+1]=laz[idx];
      seg[idx*2+1]=-laz[idx]-1;
    }
    else
    if(((laz[idx*2+1]<0)?-laz[idx*2+1]:laz[idx*2+1])>-laz[idx])
    {
      laz[idx*2+1]=laz[idx];
      seg[idx*2+1]=-laz[idx]-1;
    }
  }
  else
  { 
    if(laz[idx*2]==INF)
    {
      laz[idx*2]=laz[idx];
      seg[idx*2]=laz[idx]-1;
    }
    else
    if(((laz[idx*2]<0)?-laz[idx*2]:laz[idx*2])<laz[idx])
    {
      laz[idx*2]=laz[idx];
      seg[idx*2]=laz[idx]-1;
    }
 
    if(laz[idx*2+1]==INF)
    {
      laz[idx*2+1]=laz[idx];
      seg[idx*2+1]=laz[idx]-1;
    }
    else
    if(((laz[idx*2+1]<0)?-laz[idx*2+1]:laz[idx*2+1])<laz[idx])
    {
      laz[idx*2+1]=laz[idx];
      seg[idx*2+1]=laz[idx]-1;
    }
  }
  laz[idx]=INF;
  seg[idx]=0;
}
 
void build(int l,int r,int idx)
{
  laz[idx]=INF;
  if(l==r)
    return ;
  
  build(l,(l+r)/2,idx*2);
  build((l+r)/2+1,r,idx*2+1);
}
 
void up(int l,int r,int idx,int u,int L,int R)
{
  if(r<L || l>R)
  return ;
  if(L<=l && r<=R)
  {
    if(u<0 && seg[idx]>-u-1)
    { 
    seg[idx]=-u-1;
    laz[idx]=u;
    }
 
    if(u>0 && seg[idx]<u-1)
    {
    seg[idx]=u-1;
    laz[idx]=u;
    }
    return ;
  }

  lazy(idx);
  up(l,(l+r)/2,idx*2,u,L,R);
  up((l+r)/2+1,r,idx*2+1,u,L,R);
}
 
void fin(int l,int r,int idx)
{
  if(l==r)
  {
    ans[l]=seg[idx];
    return;
  }
  lazy(idx);
  fin(l,(l+r)/2,idx*2);
  fin((l+r)/2+1,r,idx*2+1);
}
 
void buildWall(int n, int k, int op[], int left[], int right[], int height[], int finalHeight[])
{
  build(0,n-1,1);
  for(int i=0;i<k;i++)
    up(0,n-1,1,((op[i]==1)?height[i]+1:-height[i]-1),left[i],right[i]);
  

 
  fin(0,n-1,1);
  for(int i=0;i<n;i++)
  finalHeight[i]=ans[i];
 
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 2 ms 340 KB Output is correct
3 Incorrect 1 ms 340 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 117 ms 8036 KB Output is correct
3 Incorrect 150 ms 4784 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 2 ms 340 KB Output is correct
3 Incorrect 1 ms 340 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 2 ms 340 KB Output is correct
3 Incorrect 2 ms 340 KB Output isn't correct
4 Halted 0 ms 0 KB -