| # | Time | Username | Problem | Language | Result | Execution time | Memory | 
|---|---|---|---|---|---|---|---|
| 69385 | MANcity | Wall (IOI14_wall) | C++14 | 0 ms | 0 KiB | 
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<iostream>
#include<cstdio>
#include<fstream>
#include<algorithm>
#include<cmath>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<cstring>
#include<vector>
#include "wall.h"
using namespace std;
#define for1(i,n) for(int i=1;i<=(int)n;i++)
#define for0(i,n) for(int i=0;i<=(int)n;i++)
#define forn(i,n) for(int i=n;i>=1;i--)
#define fo(i,x,y) for(int i=x;i<=(int)y;i++)
#define fr(i,x,y) for(int i=x;i>=(int)y;i--)
#define pb push_back
#define mp make_pair
#define LL long long
const LL Mod=1000*1000*1000+7;
struct vert
{
    int after_op;
    int do_0;
    int do_109;
    int ma;
    int mi;
}t[4*500002];
int give_value(int x,vert V)
{
    if(V.ma>=x)
        return V.do_0;
    if(V.mi<=x)
        return V.do_109;
    return x;
}
vert combine(vert V1,vert V2)
{
    vert V;
    V.after_op=give_value(V1.after_op,V2);
    V.do_0=give_value(V1.do_0,V2);
    V.do_109=give_value(V1.do_109,V2);
    V.ma=max(V1.ma,V2.ma);
    V.mi=min(V1.mi,V2.mi);
    return V;
}
int U=0;
void update(int left,int right,int pos,int v,pair<int,int> val)
{
    if(left==right)
    {
        if(val.first==0)
        {
            t[v].after_op=0;
            t[v].do_0=0;
            t[v].do_109=val.second;
            t[v].mi=val.second;
            t[v].ma=0;
        }
        if(val.first==1)
        {
            t[v].after_op=val.second;
            t[v].do_0=val.second;
            t[v].do_109=0;
            t[v].ma=val.second;
            t[v].mi=100000000;
        }
    }
    else
    {
        int m=(left+right)/2;
        if(pos<=m)
            update(left,m,pos,2*v,val);
        else
            update(m+1,right,pos,2*v+1,val);
        t[v]=combine(t[2*v],t[2*v+1]);
    }
}
vector<pair<int,pair<int,int> > > aj[2000002];
vector<pair<int,pair<int,int> > > dzax[2000002];
void buildWall(int n, int k, int op[], int left[], int right[], int height[], int finalHeight[])
{
    for0(i,k-1)
    {
        aj[left[i]].pb({i,{height[i],2-op[i]}});
        dzax[right[i]].pb({i,{10000000,0}});
    }
    for0(i,k-1)
        update(0,k-1,i,1,{0,100000000});
    for0(i,n-1)
    {
        for0(j,aj[i].size()-1)
        {
            int H=aj[i][j].second.first;
            int POS=aj[i][j].first;
            int OP=aj[i][j].second.second;
            update(0,k-1,POS,1,{OP,H});
        }
        finalHeight[i]=t[1].after_op;
        for0(j,dzax[i].size()-1)
        {
            int H=dzax[i][j].second.first;
            int POS=dzax[i][j].first;
            int OP=dzax[i][j].second.second;
            update(0,k-1,POS,1,{OP,H});
        }
    }
    return finalHeight;
}
/*
10 6
1 1 8 4
2 4 9 1
2 3 6 5
1 0 5 3
1 2 2 5
2 6 7 0
*/
/*
4 1
1 0 0 5
*/
