Submission #900197

# Submission time Handle Problem Language Result Execution time Memory
900197 2024-01-07T21:01:57 Z asdasdqwer Wall (IOI14_wall) C++14
0 / 100
494 ms 21336 KB
#include "wall.h"

#include <bits/stdc++.h>
using namespace std;

struct Segtree {
    int n;
    vector<int> mn;
    vector<int> mx;

    // 0 : no updates
    // 1 : last update was maximum
    // 2 : last update was minimum
    vector<int> lastUpdate;
    
    Segtree(int sz) {
        n=1;
        while(n<sz)n*=2;
        mn.assign(2*n,0);
        mx.assign(2*n,0);
        lastUpdate.assign(2*n,0);
    }

    void pushdown(int x, bool secPush) {
        if (secPush) {
            pushdown(2*x+1,false);
            pushdown(2*x+2,false);
        }

        if (lastUpdate[x] == 0) return;
        
        if (lastUpdate[x] == 1) {
            if (mx[2*x+1] > mx[x]) {
                mx[2*x+1] = mx[x];
                lastUpdate[2*x+1] = 1;
            }

            if (mx[2*x+2] > mx[x]) {
                mx[2*x+2] = mx[x];
                lastUpdate[2*x+2] = 1;
            }

            mn[2*x+1]=min(mn[2*x+1], mx[x]);
            mn[2*x+2]=min(mn[2*x+2], mx[x]);
        }

        else if (lastUpdate[x] == 2) {
            if (mn[2*x+1] < mn[x]) {
                mn[2*x+1] = mn[x];
                lastUpdate[2*x+1] = 2;
            }

            if (mn[2*x+2] < mn[x]) {
                mn[2*x+2] = mn[x];
                lastUpdate[2*x+2] = 2;
            }

            mx[2*x+1]=max(mx[2*x+1], mn[x]);
            mx[2*x+2]=max(mx[2*x+2], mn[x]);
        }

        lastUpdate[x]=0;
    }


    void setMax(int l, int r, int v, int x, int lx, int rx) {
        if (lx >= r || rx <= l) return;

        if (rx-lx==1) {
            if (mx[x] > v) {
                mx[x]=mn[x]=v;
                lastUpdate[x]=1;
            }
            return;
        }

        pushdown(x, ((rx-lx)!=2));

        if (lx >= l && rx <= r) {
            if (mx[x] > v) {
                lastUpdate[x]=1;
                mx[x]=v;
                if (mn[x] > v)mn[x]=v;
            }
            return;
        }

        int m=(lx+rx)/2;
        setMax(l,r,v,2*x+1,lx,m);
        setMax(l,r,v,2*x+2,m,rx);

        mx[x]=max(mx[2*x+1],mx[2*x+2]);
        mn[x]=min(mn[2*x+1],mn[2*x+2]);
    }

    void setMax(int l, int r, int v) {
        setMax(l, r, v, 0, 0, n);
    }

    void setMin(int l, int r, int v, int x, int lx, int rx) {
        if (lx >= r || rx <= l) return;

        if (rx-lx==1) {
            if (mn[x] < v) {
                mn[x]=mx[x]=v;
                lastUpdate[x]=2;
            }
            return;
        }

        pushdown(x, ((rx-lx)!=2));

        if (lx >= l && rx <= r) {
            if (mn[x] < v) {
                lastUpdate[x]=2;
                mn[x]=v;
                if (mx[x] < v) mx[x]=v;
            }
            return;
        }

        int m=(lx+rx)/2;
        setMin(l,r,v,2*x+1,lx,m);
        setMin(l,r,v,2*x+2,m,rx);

        mx[x]=max(mx[2*x+1],mx[2*x+2]);
        mn[x]=min(mn[2*x+1],mn[2*x+2]);
    }

    void setMin(int l, int r, int v) {
        setMin(l, r, v, 0, 0, n);
    }

    int get(int i, int x, int lx, int rx) {
        if (rx-lx==1) {
            return mx[x];
        }

        pushdown(x, ((rx-lx)!=2));

        int m=(lx+rx)/2;
        if (i<m)return get(i,2*x+1,lx,m);
        else return get(i,2*x+2,m,rx);
    }

    int get(int i) {
        return get(i,0,0,n);
    }
};


void buildWall(int n, int k, int op[], int left[], int right[], int height[], int finalHeight[]) {
    Segtree sg(n);

    for (int i=0;i<k;i++) {
        if (op[i] == 1) {
            sg.setMin(left[i], right[i]+1, height[i]);
        }

        else {
            sg.setMax(left[i], right[i]+1, height[i]);
        }
    }

    for (int i=0;i<n;i++) {
        finalHeight[i] = sg.get(i);
    }
}

# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Incorrect 2 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 352 KB Output is correct
2 Correct 109 ms 14004 KB Output is correct
3 Correct 172 ms 8316 KB Output is correct
4 Incorrect 494 ms 21336 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 356 KB Output is correct
2 Correct 2 ms 348 KB Output is correct
3 Incorrect 2 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 572 KB Output is correct
3 Incorrect 2 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -