답안 #563029

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
563029 2022-05-16T05:48:15 Z Seb 벽 (IOI14_wall) C++17
100 / 100
916 ms 99296 KB
#include <bits/stdc++.h>
#include <wall.h>

using namespace std;

typedef int ll;

ll N;

struct Node{
    ll top, bot;
    Node() : top(-1LL), bot(-1LL) {}
};

void push(Node st[], ll nodo, ll ini, ll fin) {
    if (ini!=fin) {
        if (st[nodo].top!=-1) {
            if (st[nodo*2].top!=-1) st[nodo*2].top = min(st[nodo*2].top,st[nodo].top);
            else st[nodo*2].top = st[nodo].top;
            if (st[nodo*2+1].top!=-1) st[nodo*2+1].top = min(st[nodo*2+1].top,st[nodo].top);
            else st[nodo*2+1].top = st[nodo].top;
            if (st[nodo*2].bot>st[nodo*2].top) st[nodo*2].bot = st[nodo*2].top;
            if (st[nodo*2+1].bot>st[nodo*2+1].top) st[nodo*2+1].bot = st[nodo*2+1].top;
            st[nodo].top = -1;
        }
        if (st[nodo].bot!=-1) {
            if (st[nodo*2].bot!=-1) st[nodo*2].bot = max(st[nodo*2].bot,st[nodo].bot);
            else st[nodo*2].bot = st[nodo].bot;
            if (st[nodo*2+1].bot!=-1) st[nodo*2+1].bot = max(st[nodo*2+1].bot,st[nodo].bot);
            else st[nodo*2+1].bot = st[nodo].bot;
            if (st[nodo*2].top!=-1 && st[nodo*2].bot>st[nodo*2].top) st[nodo*2].top = st[nodo*2].bot;
            if (st[nodo*2+1].top!=-1 && st[nodo*2+1].bot>st[nodo*2+1].top) st[nodo*2+1].top = st[nodo*2+1].bot;
            st[nodo].bot = -1;
        }
    }
    return;
}

void merger(Node st[], Node aux, ll nodo) {
    if (aux.top!=-1) {
        if (st[nodo].top!=-1) st[nodo].top = min(st[nodo].top,aux.top);
        else st[nodo].top = aux.top;
        if (st[nodo].bot>st[nodo].top) st[nodo].bot = st[nodo].top;
    }
    if (aux.bot!=-1) {
        if (st[nodo].bot!=-1) st[nodo].bot = max(st[nodo].bot,aux.bot);
        else st[nodo].bot = aux.bot;
        if (st[nodo].top!=-1 && st[nodo].bot>st[nodo].top) st[nodo].top = st[nodo].bot;
    }
    return;
}

void update(Node st[], ll caso, ll l, ll r, ll delta, ll nodo = 1, ll ini = 0, ll fin = N-1) {
    push(st,nodo,ini,fin);
    if (ini>r || fin<l) return;
    if (l<=ini && fin<=r) {
        Node aux;
        if (caso==1) aux.bot = delta;
        else aux.top = delta;
        merger(st,aux,nodo);
        push(st,nodo,ini,fin);
        return;
    }
    update(st,caso,l,r,delta,nodo*2,ini,(ini+fin)/2);
    update(st,caso,l,r,delta,nodo*2+1,(ini+fin)/2+1,fin);
    return;
}

void ans(Node st[], ll pos[], ll nodo = 1, ll ini = 0, ll fin = N-1) {
    push(st,nodo,ini,fin);
    if (ini==fin){
        pos[ini] = max(st[nodo].bot,0);
        return;
    }
    ans(st,pos,nodo*2,ini,(ini+fin)/2);
    ans(st,pos,nodo*2+1,(ini+fin)/2+1,fin);
    return;
}

void buildWall(int n, int k, int op[], int left[], int right[], int height[], int finalHeight[]) {
N = n;
ll i,j;
Node st[4*n];
for (i=0;i<k;i++) update(st,op[i],left[i],right[i],height[i]);
ans(st,finalHeight);
return;
}

Compilation message

wall.cpp: In function 'void buildWall(int, int, int*, int*, int*, int*, int*)':
wall.cpp:82:6: warning: unused variable 'j' [-Wunused-variable]
   82 | ll i,j;
      |      ^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 2 ms 340 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 9 ms 852 KB Output is correct
5 Correct 7 ms 852 KB Output is correct
6 Correct 7 ms 852 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 163 ms 13852 KB Output is correct
3 Correct 225 ms 7944 KB Output is correct
4 Correct 698 ms 21392 KB Output is correct
5 Correct 309 ms 22476 KB Output is correct
6 Correct 310 ms 20868 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 2 ms 340 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 8 ms 852 KB Output is correct
5 Correct 5 ms 852 KB Output is correct
6 Correct 5 ms 852 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 148 ms 13824 KB Output is correct
9 Correct 243 ms 8060 KB Output is correct
10 Correct 669 ms 21392 KB Output is correct
11 Correct 306 ms 22432 KB Output is correct
12 Correct 287 ms 20956 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 160 ms 13888 KB Output is correct
15 Correct 54 ms 1960 KB Output is correct
16 Correct 916 ms 21644 KB Output is correct
17 Correct 373 ms 21092 KB Output is correct
18 Correct 291 ms 21064 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 300 KB Output is correct
2 Correct 2 ms 340 KB Output is correct
3 Correct 3 ms 340 KB Output is correct
4 Correct 9 ms 804 KB Output is correct
5 Correct 7 ms 852 KB Output is correct
6 Correct 5 ms 852 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 135 ms 13888 KB Output is correct
9 Correct 234 ms 7964 KB Output is correct
10 Correct 650 ms 21380 KB Output is correct
11 Correct 303 ms 22448 KB Output is correct
12 Correct 294 ms 20932 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 156 ms 13832 KB Output is correct
15 Correct 47 ms 1964 KB Output is correct
16 Correct 896 ms 21716 KB Output is correct
17 Correct 289 ms 21096 KB Output is correct
18 Correct 326 ms 21068 KB Output is correct
19 Correct 760 ms 99236 KB Output is correct
20 Correct 762 ms 96792 KB Output is correct
21 Correct 747 ms 99232 KB Output is correct
22 Correct 807 ms 96896 KB Output is correct
23 Correct 741 ms 96736 KB Output is correct
24 Correct 766 ms 96812 KB Output is correct
25 Correct 754 ms 96756 KB Output is correct
26 Correct 782 ms 99240 KB Output is correct
27 Correct 839 ms 99296 KB Output is correct
28 Correct 765 ms 96956 KB Output is correct
29 Correct 780 ms 96716 KB Output is correct
30 Correct 794 ms 96716 KB Output is correct