Submission #520828

# Submission time Handle Problem Language Result Execution time Memory
520828 2022-01-31T05:53:40 Z byunjaewoo Pyramid Base (IOI08_pyramid_base) C++17
27 / 100
125 ms 5244 KB
/// B>0
#include <bits/stdc++.h>
using namespace std;
using ll=long long;

const int Nmax=30010, S=(1<<15);
int N, M, B, P, ans;
int C[Nmax];
struct Rectangle {int sx, ex, sy, ey;}A[Nmax], t[Nmax];
struct Line {int x, sy, ey, k;};

class LazyPropagation {
public:
    void Update(int l, int r, ll v) {Update(1, 1, S, l, r, v);}
    ll Query(int l, int r) {return Query(1, 1, S, l, r);}
    void init() {fill(Tree, Tree+2*S, 0); fill(Lazy, Lazy+2*S, 0);}
private:
    ll Tree[2*S], Lazy[2*S];
    void Propagate(int node, int s, int e) {
        Tree[node]+=Lazy[node];
        if(s!=e) {
            Lazy[2*node]+=Lazy[node];
            Lazy[2*node+1]+=Lazy[node];
        }
        Lazy[node]=0;
        return;
    }
    void Update(int node, int s, int e, int l, int r, int v) {
        Propagate(node, s, e);
        if(l>e || s>r) return;
        if(l<=s && e<=r) {
            Lazy[node]+=v;
            Propagate(node, s, e);
            return;
        }
        int lch=2*node, rch=lch+1, m=s+e>>1;
        Update(lch, s, m, l, r, v); Update(rch, m+1, e, l, r, v);
        Tree[node]=min(Tree[lch], Tree[rch]);
    }
    ll Query(int node, int s, int e, int l, int r) {
        Propagate(node, s, e);
        if(l>e || s>r) return INT_MAX;
        if(l<=s && e<=r) return Tree[node];
        int lch=2*node, rch=lch+1, m=s+e>>1;
        return min(Query(lch, s, m, l, r), Query(rch, m+1, e, l, r));
    }
}T;

bool chk(int x) {
    vector<Line> V;
    for(int i=1; i<=P; i++) {
        t[i]=A[i];
        t[i].sx=max(1, A[i].sx-x+1);
        t[i].sy=max(1, A[i].sy-x+1);
        V.push_back({t[i].sx, t[i].sy, t[i].ey, C[i]});
        V.push_back({t[i].ex+1, t[i].sy, t[i].ey, -C[i]});
    }
    V.push_back({1, 0, 0, 0});
    sort(V.begin(), V.end(), [](Line a, Line b) {return a.x<b.x;});
    T.init();
    for(int i=0; i<V.size(); i++) {
        if(V[i].x>N-x+1) break;
        T.Update(V[i].sy, V[i].ey, V[i].k);
        int j;
        for(j=i+1; j<V.size() && V[i].x==V[j].x; j++)
            T.Update(V[j].sy, V[j].ey, V[j].k);
        if(T.Query(1, M-x+1)<=B) return true;
        i=j-1;
    }
    return false;
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin>>N>>M>>B>>P;
    for(int i=1; i<=P; i++) {
        cin>>A[i].sx>>A[i].sy>>A[i].ex>>A[i].ey>>C[i];
    }
    for(int s=1, e=1000000; s<=e;) {
        int mid=(s+e)/2;
        if(chk(mid)) ans=mid, s=mid+1;
        else e=mid-1;
    }
    cout<<ans;
    return 0;
}

Compilation message

pyramid_base.cpp: In member function 'void LazyPropagation::Update(int, int, int, int, int, int)':
pyramid_base.cpp:36:39: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   36 |         int lch=2*node, rch=lch+1, m=s+e>>1;
      |                                      ~^~
pyramid_base.cpp: In member function 'll LazyPropagation::Query(int, int, int, int, int)':
pyramid_base.cpp:44:39: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   44 |         int lch=2*node, rch=lch+1, m=s+e>>1;
      |                                      ~^~
pyramid_base.cpp: In function 'bool chk(int)':
pyramid_base.cpp:61:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<Line>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   61 |     for(int i=0; i<V.size(); i++) {
      |                  ~^~~~~~~~~
pyramid_base.cpp:65:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<Line>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   65 |         for(j=i+1; j<V.size() && V[i].x==V[j].x; j++)
      |                    ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1356 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 1348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 1356 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 9 ms 1360 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 1480 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 1484 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 35 ms 2056 KB Output is correct
2 Correct 86 ms 2072 KB Output is correct
3 Correct 62 ms 2056 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 125 ms 3272 KB Output is correct
2 Incorrect 99 ms 3272 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 81 ms 4328 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 114 ms 4844 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 113 ms 5244 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 12 ms 2844 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 12 ms 2884 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 12 ms 2884 KB Output isn't correct
2 Halted 0 ms 0 KB -