Submission #524808

# Submission time Handle Problem Language Result Execution time Memory
524808 2022-02-10T05:05:30 Z pokmui9909 Pyramid Base (IOI08_pyramid_base) C++17
35 / 100
1224 ms 143460 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

const int S = (1 << 20);
struct Node{
    int l, r, mn, len, pfx, sfx, d;
    Node operator+(const Node &k)const{
        Node ret = {l, k.r, min(mn, k.mn), len + k.len, pfx, k.sfx, 0LL};
        if(mn == ret.mn) ret.d = max(ret.d, d);
        if(k.mn == ret.mn) ret.d = max(ret.d, k.d);
        if(pfx == len && l == k.l) ret.pfx = len + k.pfx;
        if(k.sfx == k.len && r == k.r) ret.sfx = k.len + sfx;
        if(r == k.l && r == ret.mn) ret.d = max(ret.d, sfx + k.pfx);
        return ret;
    }
};
struct SegTree{
    Node T[2 * S];
    int lazy[2 * S] = {};
    void init(int node, int s, int e){
        if(s == e){
            T[node] = {0, 0, 0, 1, 1, 1, 1};
            return;
        }
        int lch = 2 * node, rch = 2 * node + 1, m = (s + e) / 2;
        init(lch, s, m);
        init(rch, m + 1, e);
        T[node] = T[lch] + T[rch];
    }
    void propagate(int node, int s, int e){
        int lch = 2 * node, rch = 2 * node + 1;
        if(s != e){
            lazy[lch] += lazy[node], lazy[rch] += lazy[node];
        }
        T[node].l += lazy[node];
        T[node].r += lazy[node];
        T[node].mn += lazy[node];
        lazy[node] = 0;
    }
    void update(int node, int s, int e, int l, int r, int v){
        propagate(node, s, e);
        if(e < l || s > r) return;
        if(l <= s && e <= r){
            lazy[node] += v;
            propagate(node, s, e);
            return;
        }
        int lch = 2 * node, rch = 2 * node + 1, m = (s + e) / 2;
        update(lch, s, m, l, r, v);
        update(rch, m + 1, e, l, r, v);
        T[node] = T[lch] + T[rch];
    }
    int query(){
        return (T[1].mn == 0 ? T[1].d : 0);
    }
};
SegTree ST;
struct Line{
    int y1, y2, c;
};
vector<Line> L[1000005], R[1000005];
int M, N, P, B;

int main(){
    cin.tie(0) -> sync_with_stdio(false);
   
    cin >> M >> N >> B >> P;
    for(int i = 1; i <= P; i++){
        int x1, y1, x2, y2, c;
        cin >> x1 >> y1 >> x2 >> y2 >> c;
        if(B == 0) c = 1;
        L[x1].push_back({y1, y2, c});
        R[x2].push_back({y1, y2, -c});
    }
    int ans = 0;
    int S = 1, E = 1;
    ST.init(1, 1, N);
    for(auto i : L[1]) ST.update(1, 1, N, i.y1, i.y2, i.c);
    while(S <= E && E <= M){
        int v = ST.query();
        if(v >= E - S + 1){
            ans = max(ans, E - S + 1);
            E++;
            for(auto i : L[E]) ST.update(1, 1, N, i.y1, i.y2, i.c);
        } else {
            for(auto i : R[S]) ST.update(1, 1, N, i.y1, i.y2, i.c);
            S++;
        }
    }
    cout << ans;
}
# Verdict Execution time Memory Grader output
1 Correct 26 ms 55364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 32 ms 55488 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 28 ms 55540 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 29 ms 56392 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 35 ms 62732 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 62 ms 112968 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 75 ms 112988 KB Output is correct
2 Incorrect 69 ms 112972 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 47 ms 56624 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 58 ms 63548 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 128 ms 114164 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 138 ms 114472 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 188 ms 114696 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 734 ms 124340 KB Output is correct
2 Correct 369 ms 74116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 982 ms 129376 KB Output is correct
2 Incorrect 386 ms 134900 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1224 ms 134192 KB Output is correct
2 Correct 495 ms 143460 KB Output is correct
3 Incorrect 448 ms 143300 KB Output isn't correct
4 Halted 0 ms 0 KB -