Submission #1043633

# Submission time Handle Problem Language Result Execution time Memory
1043633 2024-08-04T12:38:11 Z vanea Wall (IOI14_wall) C++14
100 / 100
994 ms 68696 KB
#include <bits/stdc++.h>
#include "wall.h"
using namespace std;
using ll = long long;
using ld = long double;

const int mxN = 1e7;
const int INF = 1e9+10;

array<int, 2> st[mxN];

void build(int node, int l, int r) {
    if(l == r) {
        st[node] = {0, INF};
        return ;
    }
    int mid = (l+r)/2;
    build(node*2, l, mid);
    build(node*2+1, mid+1, r);
    st[node] = {0, INF};
}

void propagate(int node, int l, int r) {
    if(l == r) return ;
    int left = node*2, right = node*2+1;
    st[left][0] = max(st[left][0], st[node][0]);
    st[left][1] = min(st[left][1], st[node][1]);
    st[right][0] = max(st[right][0], st[node][0]);
    st[right][1] = min(st[right][1], st[node][1]);
    st[left][1] = max(st[left][1], st[node][0]);
    st[left][0] = min(st[left][0], st[node][1]);
    st[right][0] = min(st[right][0], st[node][1]);
    st[right][1] = max(st[right][1], st[node][0]);
    st[node][0] = 0; st[node][1] = INF;
}

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) {
            st[node][0] = max(st[node][0], h);
            st[node][1] = max(st[node][1], h);
        }
        else {
            st[node][1] = min(st[node][1], h);
            st[node][0] = min(st[node][0], h);
        }
        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);
}

int query(int node, int l, int r, int k) {
    propagate(node, l, r);
    if(l == r && l == k) {
        return min(st[node][0], st[node][1]);
    }
    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[]) {
    build(1, 0, n-1);
    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);
    }
}
/*
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    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 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 5 ms 2908 KB Output is correct
5 Correct 4 ms 2876 KB Output is correct
6 Correct 4 ms 2868 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 67 ms 8220 KB Output is correct
3 Correct 113 ms 6012 KB Output is correct
4 Correct 325 ms 11068 KB Output is correct
5 Correct 212 ms 11596 KB Output is correct
6 Correct 222 ms 11340 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 Correct 1 ms 348 KB Output is correct
4 Correct 5 ms 2908 KB Output is correct
5 Correct 6 ms 2872 KB Output is correct
6 Correct 5 ms 3020 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 69 ms 13608 KB Output is correct
9 Correct 111 ms 9556 KB Output is correct
10 Correct 367 ms 19972 KB Output is correct
11 Correct 219 ms 20564 KB Output is correct
12 Correct 213 ms 19504 KB Output is correct
13 Correct 1 ms 600 KB Output is correct
14 Correct 75 ms 13540 KB Output is correct
15 Correct 24 ms 3672 KB Output is correct
16 Correct 335 ms 20308 KB Output is correct
17 Correct 227 ms 19700 KB Output is correct
18 Correct 229 ms 19792 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 480 KB Output is correct
4 Correct 5 ms 2908 KB Output is correct
5 Correct 5 ms 2876 KB Output is correct
6 Correct 5 ms 2908 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 71 ms 13464 KB Output is correct
9 Correct 124 ms 9560 KB Output is correct
10 Correct 351 ms 20052 KB Output is correct
11 Correct 218 ms 20760 KB Output is correct
12 Correct 218 ms 19312 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 72 ms 13392 KB Output is correct
15 Correct 25 ms 3672 KB Output is correct
16 Correct 343 ms 20124 KB Output is correct
17 Correct 230 ms 19536 KB Output is correct
18 Correct 229 ms 19540 KB Output is correct
19 Correct 925 ms 68692 KB Output is correct
20 Correct 913 ms 66132 KB Output is correct
21 Correct 919 ms 68696 KB Output is correct
22 Correct 994 ms 66248 KB Output is correct
23 Correct 956 ms 66128 KB Output is correct
24 Correct 951 ms 66340 KB Output is correct
25 Correct 916 ms 66220 KB Output is correct
26 Correct 956 ms 68692 KB Output is correct
27 Correct 926 ms 68672 KB Output is correct
28 Correct 934 ms 66320 KB Output is correct
29 Correct 925 ms 66292 KB Output is correct
30 Correct 925 ms 66132 KB Output is correct