Submission #1346907

#TimeUsernameProblemLanguageResultExecution timeMemory
1346907DangKhoizzzzWall (IOI14_wall)C++20
100 / 100
557 ms59148 KiB


#include <bits/stdc++.h>
#define arr3 array <int , 3>
#define pii pair <int , int>
#define fi first
#define se second
#define BIT(x , k) ((x >> k)&1)
#define MASK(x) (1 << x)
#include "wall.h"

using namespace std;

const int maxn = 2e6 + 7;
const int INF = 1e9;

struct node
{
    int maxval , minval;
    node(){}
    node(int x , int y) {maxval = y; minval = x;}
};

node st[maxn*4];

node apply(node a , node b)
{
    if(b.minval > a.maxval) return node(b.minval , b.minval);
    if(b.maxval < a.minval) return node(b.maxval , b.maxval);
    return node(max(a.minval , b.minval) , min(a.maxval , b.maxval));
}
void down(int id , int l , int r)
{
    if(l != r)
    {
        st[id*2] = apply(st[id*2] , st[id]);
        st[id*2+1] = apply(st[id*2+1] , st[id]);
        st[id] = node(0 , INF);
    }
}
void update(int id , int l , int r , int u , int v , node val)
{
    down(id , l , r);
    if(r < u || l > v || l > r) return;
    if(u <= l && r <= v)
    {
        st[id] = apply(st[id] , val);
        down(id , l , r);
        return;
    }
    int mid = (l+r)>>1;
    update(id*2 , l , mid , u , v, val);
    update(id*2+1 , mid+1 , r , u , v , val);
}
int get(int id , int l , int r , int pos)
{
    down(id , l , r);
    if(l == r) return st[id].minval;
    int mid = (l+r)>>1;
    if(pos <= mid) return get(id*2 , l , mid , pos);
    else return get(id*2+1 , mid+1 , r , pos);
}


void buildWall(int n, int k, int op[], int left[], int right[], int height[], int finalHeight[])
{
    update(1 , 0 , n-1 , 0 , n-1 , node(0 , 0));
    for(int i = 0; i < k; i++)
    {
        if(op[i] == 1)
        {
            update(1 , 0 , n-1 , left[i] , right[i] , node(height[i] , INF));
        }
        else
        {
            update(1 , 0 , n-1 , left[i] , right[i] , node(0 , height[i]));
        }
    }
    for(int i = 0; i < n; i++) finalHeight[i] = get(1 , 0 , n-1 , i);
    return;
}


#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...