답안 #877241

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
877241 2023-11-23T04:43:08 Z GaLz 벽 (IOI14_wall) C++14
100 / 100
740 ms 129484 KB
#include <bits/stdc++.h>
#include "wall.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
const int maxn=2e6+5;
const int INF=1e9+5;
const ll mod=1e9+7;
#define ok ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pb push_back
#define lb lower_bound
#define ub upper_bpund
#define fi first
#define se second
#define endl '\n'
struct Node {
    int max1, max2, min1, min2, lazy;
} seg[maxn*4];
int arr[maxn];
vi ans;
void merge(int now) {
    if(seg[now*2].max1==seg[now*2+1].max1) {
        seg[now].max1=seg[now*2].max1;
        seg[now].max2=max(seg[now*2].max2, seg[now*2+1].max2);
    } else {
        if(seg[now*2].max1>seg[now*2+1].max1) {
            seg[now].max1=seg[now*2].max1;
            seg[now].max2=max(seg[now*2].max2, seg[now*2+1].max1);
        } else {
            seg[now].max1=seg[now*2+1].max1;
            seg[now].max2=max(seg[now*2].max1, seg[now*2+1].max2);
        }
    }
    if(seg[now*2].min1==seg[now*2+1].min1) {
        seg[now].min1=seg[now*2].min1;
        seg[now].min2=min(seg[now*2].min2, seg[now*2+1].min2);
    } else {
        if(seg[now*2].min1<seg[now*2+1].min1) {
            seg[now].min1=seg[now*2].min1;
            seg[now].min2=min(seg[now*2].min2, seg[now*2+1].min1);
        } else {
            seg[now].min1=seg[now*2+1].min1;
            seg[now].min2=max(seg[now*2].min1, seg[now*2+1].min2);
        }
    }
}
// chmin update
void push_max(int now, int l, int r, int val) {
    if(val>=seg[now].max1) return;
    seg[now].max1=val;
    if(l==r) {
        seg[now].min1=seg[now].max1;
    } else {
        if(val<=seg[now].min1) {
            seg[now].min1=val;
        } else if(val<seg[now].min2) {
            seg[now].min2=val;
        }
    }
}
// chmax update
void push_min(int now, int l, int r, int val) {
    if(val<=seg[now].min1) return;
    seg[now].min1=val;
    if(l==r) {
        seg[now].max1=seg[now].min1;
    } else {
        if(val>=seg[now].max1) {
            seg[now].max1=val;
        } else if(val>seg[now].max2) {
            seg[now].max2=val;
        }
    }
}
void pushdown(int now, int l, int r) {
    if(l==r) return;
    int mid=(l+r)/2;
    push_max(now*2, l, mid, seg[now].max1);
    push_max(now*2+1, mid+1, r, seg[now].max1);
    push_min(now*2, l, mid, seg[now].min1);
    push_min(now*2+1, mid+1, r, seg[now].min1);
}
void build(int now, int l, int r) {
    if(l==r) {
        seg[now].max1=seg[now].min1=arr[l];
        seg[now].max2=-INF;
        seg[now].min2=INF;
    } else {
        int mid=(l+r)/2;
        build(now*2, l, mid);
        build(now*2+1, mid+1, r);
        merge(now);
    }
}
void update_chmin(int now, int l, int r, int posl, int posr, int val) {
    if(l>posr || r<posl || val>=seg[now].max1) return;
    if(l>=posl && r<=posr && val>seg[now].max2) {
        push_max(now, l, r, val);
        return;
    }
    pushdown(now, l, r);
    int mid=(l+r)/2;
    update_chmin(now*2, l, mid, posl, posr, val);
    update_chmin(now*2+1, mid+1, r, posl, posr, val);
    merge(now);
}
void update_chmax(int now, int l, int r, int posl, int posr, int val) {
    if(l>posr || r<posl || val<=seg[now].min1) return;
    if(l>=posl && r<=posr && val<seg[now].min2) {
        push_min(now, l, r, val);
        return;
    }
    pushdown(now, l, r);
    int mid=(l+r)/2;
    update_chmax(now*2, l, mid, posl, posr, val);
    update_chmax(now*2+1, mid+1, r, posl, posr, val);
    merge(now);
}
void query(int now, int l, int r) {
    if(l==r) {
        ans.pb(seg[now].max1);
        return;
    }
    pushdown(now, l, r);
    int mid=(l+r)/2;
    query(now*2, l, mid);
    query(now*2+1, mid+1, r);
}
void buildWall(int n, int k, int op[], int left[], int right[], int height[], int finalHeight[]) {
    build(1, 1, n);
    for(int i=0; i<k; i++) {
        if(op[i]==1) {
            update_chmax(1, 1, n, left[i]+1, right[i]+1, height[i]);
        } else if(op[i]==2) {
            update_chmin(1, 1, n, left[i]+1, right[i]+1, height[i]);
        }
    }
    query(1, 1, n);
    for(int i=0; i<n; i++) finalHeight[i]=ans[i];
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2392 KB Output is correct
2 Correct 2 ms 2396 KB Output is correct
3 Correct 2 ms 2500 KB Output is correct
4 Correct 6 ms 4700 KB Output is correct
5 Correct 5 ms 4808 KB Output is correct
6 Correct 5 ms 4696 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 113 ms 15952 KB Output is correct
3 Correct 58 ms 11856 KB Output is correct
4 Correct 142 ms 27008 KB Output is correct
5 Correct 156 ms 28364 KB Output is correct
6 Correct 183 ms 26488 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2396 KB Output is correct
2 Correct 2 ms 2500 KB Output is correct
3 Correct 2 ms 2396 KB Output is correct
4 Correct 6 ms 4700 KB Output is correct
5 Correct 5 ms 4696 KB Output is correct
6 Correct 5 ms 4700 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 114 ms 16108 KB Output is correct
9 Correct 58 ms 11808 KB Output is correct
10 Correct 138 ms 27072 KB Output is correct
11 Correct 169 ms 28188 KB Output is correct
12 Correct 186 ms 26568 KB Output is correct
13 Correct 1 ms 2392 KB Output is correct
14 Correct 111 ms 16152 KB Output is correct
15 Correct 31 ms 5856 KB Output is correct
16 Correct 558 ms 27348 KB Output is correct
17 Correct 300 ms 26828 KB Output is correct
18 Correct 310 ms 26852 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2396 KB Output is correct
2 Correct 2 ms 2396 KB Output is correct
3 Correct 2 ms 2396 KB Output is correct
4 Correct 6 ms 4808 KB Output is correct
5 Correct 5 ms 4696 KB Output is correct
6 Correct 5 ms 4700 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 114 ms 16124 KB Output is correct
9 Correct 57 ms 11836 KB Output is correct
10 Correct 142 ms 27080 KB Output is correct
11 Correct 159 ms 28064 KB Output is correct
12 Correct 190 ms 26504 KB Output is correct
13 Correct 1 ms 2392 KB Output is correct
14 Correct 123 ms 16116 KB Output is correct
15 Correct 32 ms 5840 KB Output is correct
16 Correct 556 ms 27340 KB Output is correct
17 Correct 313 ms 26788 KB Output is correct
18 Correct 310 ms 26828 KB Output is correct
19 Correct 740 ms 128336 KB Output is correct
20 Correct 725 ms 126032 KB Output is correct
21 Correct 712 ms 128248 KB Output is correct
22 Correct 704 ms 125868 KB Output is correct
23 Correct 714 ms 126244 KB Output is correct
24 Correct 691 ms 126664 KB Output is correct
25 Correct 694 ms 126388 KB Output is correct
26 Correct 706 ms 129484 KB Output is correct
27 Correct 700 ms 129204 KB Output is correct
28 Correct 710 ms 126384 KB Output is correct
29 Correct 717 ms 126432 KB Output is correct
30 Correct 696 ms 126260 KB Output is correct