답안 #842616

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
842616 2023-09-03T06:21:15 Z WLZ 벽 (IOI14_wall) C++17
100 / 100
1247 ms 219812 KB
#include "wall.h"
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <utility>
using namespace std;
typedef pair<int, int> ii;
enum state {
    BUILD, DESTROY
};

struct node {
    int i, j;
    node *left, *right;
    int max_height, min_height;
    int lazy_u, lazy_d;

    void combine(int h, state op) {
        if (h == -1) return;
                
        if (op == BUILD) {
            this->lazy_u = max(this->lazy_u, h);
            if (h > this->lazy_d && this->lazy_d != -1) {
                this->lazy_d = h;
            }
        } else if (op == DESTROY) {
            if (this->lazy_d == -1) {
                this->lazy_d = h;
            } else {
                this->lazy_d = min(this->lazy_d, h);
            }
            if (h < this->lazy_u) {
                this->lazy_u = h;
            }
        }
    }
};

node *build(int i, int j) {
    if (i == j) {
        return new node{i, j, NULL, NULL, 0, 0, -1, -1};
    }
    node *left = build(i, (i + j) / 2);
    node *right = build((i + j) / 2 + 1, j);
    return new node{i, j, left, right, 0, 0, -1, -1};
}

void propagate(node *cur) {
    /* update current node */
    if (cur->lazy_u != -1) {
        cur->max_height = max(cur->max_height, cur->lazy_u);
        cur->min_height = max(cur->min_height, cur->lazy_u);
    }
    if (cur->lazy_d != -1) {
        cur->min_height = min(cur->min_height, cur->lazy_d);
        cur->max_height = min(cur->max_height, cur->lazy_d);
    }
    /* update child */
    if (cur->left != NULL) {
        cur->left->combine(cur->lazy_u,BUILD);
        cur->left->combine(cur->lazy_d,DESTROY);
        cur->right->combine(cur->lazy_u,BUILD);
        cur->right->combine(cur->lazy_d,DESTROY);
    }
    cur->lazy_d = cur->lazy_u = -1;
}

int query(node *cur, int i) {
    propagate(cur);
    if (cur->j < i || cur->i > i) return 0;
    if (cur->i == i && cur->j == i) {
        return cur->max_height;
    }
    return query(cur->left, i) + query(cur->right, i);
}

void update(state op, int i, int j, int h, node *cur) {
    propagate(cur);
    if (cur->j < i || cur->i > j) {
        return;
    }
    if (cur->i >= i && cur->j <= j) {
        cur->combine(h, op);        
        return;
    }
    update(op, i, j, h, cur->left);
    update(op, i, j, h, cur->right);
    if (op == BUILD) {
        cur->max_height = max(cur->max_height, h);
        cur->min_height = max(cur->min_height, h);
    }
    if (op == DESTROY) {
        cur->max_height = min(cur->max_height, h);
        cur->min_height = min(cur->min_height, h);
    }
    return;
}

void buildWall(int n, int k, int op[], int left[], int right[], int height[], int finalHeight[]) {
    node *root = build(0, n - 1);
    for (int i = 0 ; i < k; i++) {
        if (op[i] == 1) {
            update(BUILD, left[i], right[i], height[i], root);
        } else if (op[i] == 2) {
            update(DESTROY, left[i], right[i], height[i], root);
        }
    }
    for (int i = 0; i < n; i++) {
        finalHeight[i] = query(root, i);
    }
    return;
}

/*int main() {
    int n, k;
	scanf("%d %d", &n, &k);
    //int op[5], left[5], right[5], height[5];
    int *op, *left, *right, *height;
    op = (int *) malloc (sizeof (int) * 500005);
    left = (int *) malloc (sizeof (int) * 500005);
    right = (int *) malloc (sizeof (int) * 500005);
    height = (int *) malloc (sizeof (int) * 500005);
	//int op[500005], left[500005], right[500005], height[500005];
	for (int i = 0; i < k; i++) {
		scanf("%d %d %d %d",op+i,&left[i], &right[i], &height[i]);
	}
	int *finalHeight = (int *) malloc (sizeof (int) * 2000005);
	buildWall(n, k, op, left, right, height, finalHeight);
	for (int i = 0; i < n; i++) {
		printf("%d\n", finalHeight[i]);
	}
	return 0;
}*/
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 2 ms 348 KB Output is correct
4 Correct 9 ms 1564 KB Output is correct
5 Correct 6 ms 1392 KB Output is correct
6 Correct 6 ms 1372 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 118 ms 11344 KB Output is correct
3 Correct 178 ms 7760 KB Output is correct
4 Correct 659 ms 23624 KB Output is correct
5 Correct 275 ms 23868 KB Output is correct
6 Correct 290 ms 23544 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 2 ms 484 KB Output is correct
4 Correct 10 ms 1576 KB Output is correct
5 Correct 6 ms 1628 KB Output is correct
6 Correct 6 ms 1372 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 112 ms 11520 KB Output is correct
9 Correct 175 ms 7764 KB Output is correct
10 Correct 721 ms 23532 KB Output is correct
11 Correct 277 ms 23888 KB Output is correct
12 Correct 282 ms 23532 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 115 ms 11336 KB Output is correct
15 Correct 48 ms 3152 KB Output is correct
16 Correct 903 ms 23792 KB Output is correct
17 Correct 297 ms 23272 KB Output is correct
18 Correct 299 ms 23164 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 432 KB Output is correct
3 Correct 2 ms 348 KB Output is correct
4 Correct 9 ms 1456 KB Output is correct
5 Correct 6 ms 1372 KB Output is correct
6 Correct 6 ms 1372 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 111 ms 11328 KB Output is correct
9 Correct 180 ms 7808 KB Output is correct
10 Correct 679 ms 23564 KB Output is correct
11 Correct 276 ms 24148 KB Output is correct
12 Correct 277 ms 23596 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 113 ms 11496 KB Output is correct
15 Correct 50 ms 3076 KB Output is correct
16 Correct 877 ms 23868 KB Output is correct
17 Correct 284 ms 23208 KB Output is correct
18 Correct 291 ms 23196 KB Output is correct
19 Correct 1205 ms 219704 KB Output is correct
20 Correct 1241 ms 217108 KB Output is correct
21 Correct 1232 ms 219728 KB Output is correct
22 Correct 1209 ms 217312 KB Output is correct
23 Correct 1231 ms 217368 KB Output is correct
24 Correct 1218 ms 217436 KB Output is correct
25 Correct 1247 ms 217416 KB Output is correct
26 Correct 1201 ms 219812 KB Output is correct
27 Correct 1236 ms 219692 KB Output is correct
28 Correct 1219 ms 217136 KB Output is correct
29 Correct 1232 ms 217244 KB Output is correct
30 Correct 1220 ms 217224 KB Output is correct