Submission #1042928

# Submission time Handle Problem Language Result Execution time Memory
1042928 2024-08-03T14:54:45 Z vanea Wall (IOI14_wall) C++14
24 / 100
448 ms 25136 KB
#include <bits/stdc++.h>
#include "wall.h"
using namespace std;
using ll = long long;

const int mxN = 1e7;

array<ll, 2> st[mxN];
array<bool, 2> vis[mxN];
int last[mxN];

void propagate(int node, int l, int r) {
    if(vis[node][0]) {
        if(l != r) {
            int left = node*2, right = node*2+1;
            if(vis[left][0]) {
                if(st[node][0] > st[left][0]) {
                    last[left] = 1;
                    st[left][0] = st[node][0];
                }
            }
            else {
                last[left] = 1;
                st[left][0] = st[node][0];
            }
            if(vis[left][1] &&
               last[left] == 2 && st[node][0] > st[left][1]) {
                st[left][1] = st[node][0];
            }
            if(vis[right][0]) {
                if(st[node][0] >= st[right][0]) {
                    last[right] = 1;
                    st[right][0] = st[node][0];
                }
            }
            else {
                last[right] = 1;
                st[right][0] = st[node][0];
            }
            if(vis[right][1] &&
               last[right] == 2 && st[node][0] > st[right][1]) {
                st[right][1] = st[node][0];
            }
            vis[left][0] = vis[right][0] = true;
            vis[node][0] = false;
        }
    }
    if(vis[node][1]) {
        if(l != r) {
            int left = node*2, right = node*2+1;
            if(vis[left][1]) {
                if(st[node][1] <= st[left][1]) {
                    st[left][1] = st[node][1];
                    last[left] = 2;
                }
            }
            else {
                st[left][1] = st[node][1];
                last[left] = 2;
            }
            if(last[left] == 1 && vis[left][0] && st[node][1] < st[left][0]) {
                st[left][0] = st[node][1];
            }
            if(vis[right][1]) {
                if(st[node][1] <= st[right][1]) {
                    st[right][1] = st[node][1];
                    last[right] = 2;
                }
            }
            else {
                st[right][1] = st[node][1];
                last[right] = 2;
            }
            if(last[right] == 1 && vis[right][0] && st[node][1] < st[right][0]) {
                st[right][0] = st[node][1];
            }
            vis[left][1] = vis[right][1] = true;
            vis[node][1] = false;
        }
    }
}

void upd(int node, int l, int r, int l1, int r1, int h, int op) {
    propagate(node, l, r);
    if(l1 <= l && r1 >= r) {
        if(op == 1) {
            if(vis[node][0]) {
                if(h >= st[node][0]) {
                    last[node] = 1;
                    st[node][0] = h;
                }
            }
            else {
                last[node] = 1;
                st[node][0] = h;
            }
            if(last[node] == 2 && vis[node][1] && h > st[node][1]) {
                st[node][1] = h;
            }
            vis[node][0] = true;
        }
        else {
            if(vis[node][1]) {
                if(h <= st[node][1]) {
                    last[node] = 2;
                    st[node][1] = h;
                }
            }
            else {
                last[node] = 2;
                st[node][1] = h;
            }
            if(last[node] == 1 && vis[node][0] && h < st[node][0]) {
                st[node][0] = h;
            }
            vis[node][1] = true;
        }
        propagate(node, l, r);
        return ;
    }
    if(l1 > r || r1 < l) return ;
    int mid = (l+r)/2;
    upd(node*2, l, mid, l1, r1, h, op);
    upd(node*2+1, mid+1, r, l1, r1, h, op);
}

ll query(int node, int l, int r, int k) {
    propagate(node, l, r);
    if(l == r && l == k) {
        ll ans = 0;
        if(vis[node][0] && vis[node][1]) {
            if(last[node] == 1) {
                ans = st[node][0];
            }
            else {
                ans = min(st[node][0], st[node][1]);
            }
        }
        else if(vis[node][0]) {
            ans = st[node][0];
        }
        return ans;
    }
    if(l > k || r < k) return 0;
    int mid = (l+r)/2;
    return query(node*2, l, mid, k) + query(node*2+1, mid+1, r, k);
}

void buildWall(int n, int k, int op[], int left[], int right[], int height[], int finalHeight[]) {
    for(int i = 0; i < k; i++) {
        upd(1, 0, n-1, left[i], right[i], height[i], op[i]);
    }
    for(int i = 0; i < n; i++) {
        finalHeight[i] = query(1, 0, n-1, i);
        //cout << finalHeight[i] << ' ';
    }
}

/*
int main()
{
    int arr1[10] = {1, 2, 2, 1, 1, 2}, arr2[10] = {1, 4, 3, 0, 2, 6};
    int arr3[10] = {8, 9, 6, 5, 2, 7}, arr4[10] = {4, 1, 5, 3, 5, 0};
    int arr5[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
    buildWall(10, 6, arr1, arr2, arr3, arr4, arr5);
}*/
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 456 KB Output is correct
3 Incorrect 1 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 77 ms 14260 KB Output is correct
3 Correct 162 ms 8964 KB Output is correct
4 Correct 448 ms 23892 KB Output is correct
5 Correct 188 ms 25136 KB Output is correct
6 Correct 167 ms 23380 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Incorrect 1 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 580 KB Output is correct
3 Incorrect 1 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -