답안 #831098

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
831098 2023-08-19T17:50:02 Z jasmin 벽 (IOI14_wall) C++17
100 / 100
636 ms 141580 KB
// ioi 14 day 1
#include<bits/stdc++.h>
using namespace std;

const int INF=1e9+7;

pair<int,int> zero={0, INF};
struct segtree{
    vector<pair<int,int> > tree;
    vector<pair<int,int> > lazy;

    segtree(int n){
        tree.assign(n*4, zero);
        lazy.assign(n*4, zero);
    }

    pair<int,int> add_update(pair<int,int> a, pair<int,int> b){

        a.first = max(a.first, b.first);
        a.second = max(a.second, b.first);

        a.second = min(a.second, b.second);

        return a;
    }

    void update_node(int l, int r, int v, pair<int,int> val){

        tree[v] = add_update(tree[v], val);
        lazy[v] = add_update(lazy[v], val);
    }

    void propagate(int l, int r, int v){
        if(lazy[v]==zero) return;

        int m=l+(r-l)/2;
        update_node(l, m, v*2+1, lazy[v]);
        update_node(m, r, v*2+2, lazy[v]);

        lazy[v]=zero;
    }

    void update_range(int l, int r, int v, int ql, int qr, pair<int,int> val){
        //cout << "update range " << l << " " << r << " " << v << " " << ql << " " << qr << "\n" << flush;
        if(qr<=l || r<=ql) return;
        if(ql<=l && r<=qr){

            update_node(l, r, v, val);
            return;
        }
        propagate(l, r, v);

        int m=l+(r-l)/2;
        update_range(l, m, v*2+1, ql, qr, val);
        update_range(m, r, v*2+2, ql, qr, val);
    }

    pair<int,int> query(int l, int r, int v, int x){
        if(l+1==r){
            return tree[v];
        }
        propagate(l, r, v);

        int m=l+(r-l)/2;
        if(x<m){
            return query(l, m, v*2+1, x);
        }
        return query(m, r, v*2+2, x);
    }

};

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

    segtree seg(n);
    //cout << "blublub\n" << flush;
    for(int i=0; i<k; i++){

        pair<int,int> val;
        if(op[i]==1){ //adding

            val={height[i], INF};
        }
        else{ //removing

            val={0, height[i]};
        }
        seg.update_range(0, n, 0, left[i], right[i]+1, val);

        //cout << "blublub\n" << flush;
    }


    for(int i=0; i<n; i++){
        auto val = seg.query(0, n, 0, i);

        finalHeight[i] = min(val.first, val.second);
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 2 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 5 ms 1108 KB Output is correct
5 Correct 4 ms 1136 KB Output is correct
6 Correct 5 ms 1108 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 107 ms 8236 KB Output is correct
3 Correct 146 ms 4876 KB Output is correct
4 Correct 430 ms 14908 KB Output is correct
5 Correct 201 ms 14908 KB Output is correct
6 Correct 194 ms 14880 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 2 ms 440 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 5 ms 1076 KB Output is correct
5 Correct 4 ms 1108 KB Output is correct
6 Correct 5 ms 1136 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 109 ms 8136 KB Output is correct
9 Correct 142 ms 4812 KB Output is correct
10 Correct 420 ms 14912 KB Output is correct
11 Correct 203 ms 15152 KB Output is correct
12 Correct 194 ms 15172 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 123 ms 8584 KB Output is correct
15 Correct 25 ms 2268 KB Output is correct
16 Correct 418 ms 15164 KB Output is correct
17 Correct 203 ms 15164 KB Output is correct
18 Correct 200 ms 15168 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 2 ms 440 KB Output is correct
3 Correct 1 ms 360 KB Output is correct
4 Correct 5 ms 1108 KB Output is correct
5 Correct 4 ms 1108 KB Output is correct
6 Correct 4 ms 1108 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 112 ms 8180 KB Output is correct
9 Correct 145 ms 4884 KB Output is correct
10 Correct 410 ms 14848 KB Output is correct
11 Correct 205 ms 15328 KB Output is correct
12 Correct 194 ms 15168 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 113 ms 8456 KB Output is correct
15 Correct 24 ms 2264 KB Output is correct
16 Correct 427 ms 15164 KB Output is correct
17 Correct 202 ms 15176 KB Output is correct
18 Correct 198 ms 15100 KB Output is correct
19 Correct 622 ms 141504 KB Output is correct
20 Correct 614 ms 141528 KB Output is correct
21 Correct 630 ms 141512 KB Output is correct
22 Correct 626 ms 141520 KB Output is correct
23 Correct 624 ms 141576 KB Output is correct
24 Correct 619 ms 141572 KB Output is correct
25 Correct 616 ms 141568 KB Output is correct
26 Correct 627 ms 141580 KB Output is correct
27 Correct 636 ms 141476 KB Output is correct
28 Correct 625 ms 141476 KB Output is correct
29 Correct 624 ms 141520 KB Output is correct
30 Correct 623 ms 141560 KB Output is correct