Submission #782670

# Submission time Handle Problem Language Result Execution time Memory
782670 2023-07-14T07:21:31 Z Trumling Wall (IOI14_wall) C++14
Compilation error
0 ms 0 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 9999999999999
#define MOD 1000000007
#define all(x) x.begin(),x.end()

struct node
{
ll m=INF,M=0;
};
ll ans[1000000];
node seg[8000000];
void lazy(int idx)
{
  seg[idx*2].m=max(seg[idx].M,seg[idx*2].m);
  seg[idx*2].M=max(seg[idx].M,seg[idx*2].M);

  seg[idx*2].m=min(seg[idx].m,seg[idx*2].m);
  seg[idx*2].M=min(seg[idx].m,seg[idx*2].M);


  seg[idx*2+1].m=max(seg[idx].M,seg[idx*2+1].m);
  seg[idx*2+1].M=max(seg[idx].M,seg[idx*2+1].M);

  seg[idx*2+1].m=min(seg[idx].m,seg[idx*2+1].m);
  seg[idx*2+1].M=min(seg[idx].m,seg[idx*2+1].M);
  return ;
}

void up(int l,int r,int idx,int op,ll u,int L,int  R)
{
  if(l>R || r<L)
  return ;

  if(L<=l && r<=R)
  {
    if(op==1)
    {
      seg[idx].m=max(seg[idx].m,u);
      seg[idx].M=max(seg[idx].M,u);
    }
    else
    {
      seg[idx].m=min(seg[idx].m,u);
      seg[idx].M=min(seg[idx].M,u);
    }
    return ;
  }
  lazy(idx);
  up(l,(l+r)/2,idx*2,op,u,L,R);
  up((l+r)/2+1,r,idx*2+1,op,u,L,R);
}

void fin(int l,int  r,int idx)
{
  if(l==r)
  {
    ans[l]=seg[idx].M;
    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[])
{
  for(int i=0;i<k;i++)
    up(0,n-1,1,op[i],height[i],left[i],right[i]);

  

  fin(0,n-1,1);
  for(int i=0;i<n;i++)
  finalHeight[i]=ans[i];
 
}

Compilation message

Compilation timeout while compiling wall