Submission #1236181

#TimeUsernameProblemLanguageResultExecution timeMemory
1236181Zbyszek99Wall (IOI14_wall)C++20
100 / 100
444 ms69868 KiB
#include "wall.h"
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define ld long double
#define ull unsigned long long
#define ff first
#define ss second
#define pii pair<int,int>
#define pll pair<long long, long long>
#define vi vector<int>
#define vl vector<long long>
#define pb push_back
#define rep(i, b) for(int i = 0; i < (b); ++i)
#define rep2(i,a,b) for(int i = a; i <= (b); ++i)
#define rep3(i,a,b,c) for(int i = a; i <= (b); i+=c)
#define count_bits(x) __builtin_popcountll((x))
#define all(x) (x).begin(),(x).end()
#define siz(x) (int)(x).size()
#define forall(it,x) for(auto& it:(x))
using namespace __gnu_pbds;
using namespace std;
typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update> ordered_set;
mt19937 mt;void random_start(){mt.seed(chrono::time_point_cast<chrono::milliseconds>(chrono::high_resolution_clock::now()).time_since_epoch().count());}
ll los(ll a, ll b) {return a + (mt() % (b-a+1));}
const int INF = 1e9+50;
const ll INF_L = 1e18+40;
const ll MOD = 1e9+7;

struct node
{
    int max_ = -1;
    int min_ = 1e9;
    int set_ = -1;
    node operator+(const node& other)
    {
        node res;
        if(set_ != -1)
        {
            if(other.set_ != -1)
            {
                res.set_ = other.set_;
                return res;
            }
            else
            {
                res.set_ = min(max(set_,other.max_),other.min_);
                return res;
            }
        }
        else
        {
            if(other.set_ != -1)
            {
                res.set_ = other.set_;
                return res;
            }
            if((other.min_ <= min_ && other.min_ >= max_) || (other.max_ <= min_ && other.max_ >= max_) || (min_ <= other.min_ && min_ >= other.max_) || (max_ <= other.min_ && max_ >= other.max_))
            {
                res.min_ = min(min_,other.min_);
                res.max_ = max(max_,other.max_);
                return res;
            }
            if(other.min_ < min_)
            {
                res.set_ = other.min_;
                return res;
            }
            else
            {
                res.set_ = other.max_;
                return res;
            }
        }
    }
};

const int tree_siz = 2048*2048-1;
node drzewo[tree_siz+1];
int ans[tree_siz/2+10];
node base;

void add_seg(int akt, int p1, int p2, int s1, int s2, node a)
{
    if(p2 < s1 || p1 > s2) return;
    if(p1 >= s1 && p2 <= s2)
    {
        drzewo[akt] = drzewo[akt] + a;
        return;
    }
    drzewo[akt*2] = drzewo[akt*2] + drzewo[akt];
    drzewo[akt*2+1] = drzewo[akt*2+1] + drzewo[akt];
    drzewo[akt] = base;
    add_seg(akt*2,p1,(p1+p2)/2,s1,s2,a);
    add_seg(akt*2+1,(p1+p2)/2+1,p2,s1,s2,a);
}

void dfs(int akt, int p1, int p2, node a)
{
    a = drzewo[akt] + a;
    if(p1 == p2)
    {
        ans[p1] = a.set_;
        return;
    }
    dfs(akt*2,p1,(p1+p2)/2,a);
    dfs(akt*2+1,(p1+p2)/2+1,p2,a);
}

void buildWall(int n, int k, int op[], int left[], int right[], int height[], int finalHeight[])
{   
    node zero;
    zero.set_ = 0;
    add_seg(1,0,tree_siz/2,0,tree_siz/2,zero);
    rep(i,k)
    {
        node add;
        if(op[i] == 1)
        {
            add.max_ = height[i];
        }
        else
        {
            add.min_ = height[i];
        }
        add_seg(1,0,tree_siz/2,left[i],right[i],add);
    }
    dfs(1,0,tree_siz/2,base);
    rep(i,n) finalHeight[i] = ans[i];
}

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