Submission #520454

# Submission time Handle Problem Language Result Execution time Memory
520454 2022-01-30T03:39:23 Z pokmui9909 Pyramid Base (IOI08_pyramid_base) C++17
20 / 100
5000 ms 143256 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
 
const ll S = (1 << 21);
struct LazySegTree{
    ll T[2 * S] = {};
    ll lazy[2 * S] = {};
    void update(ll l, ll r, ll v) {update(1, 1, S, l, r, v);}
    ll query(ll l, ll r) {return query(1, 1, S, l, r);}
 
    void propagate(ll node, ll s, ll e){
        ll lch = 2 * node, rch = 2 * node + 1;
        if(s != e){
            lazy[lch] += lazy[node], lazy[rch] += lazy[node];
        }
        T[node] += lazy[node];
        lazy[node] = 0;
    }
    void update(ll node, ll s, ll e, ll l, ll r, ll v){
        propagate(node, s, e);
        if(e < l || s > r) return;
        if(l <= s && e <= r){
            lazy[node] += v;
            propagate(node, s, e);
            return;
        }
        ll 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] = min(T[lch], T[rch]);
    }
    ll query(ll node, ll s, ll e, ll l, ll r){
        propagate(node, s, e);
        if(e < l || s > r) return 1e15;
        if(l <= s && e <= r) return T[node];
        ll lch = 2 * node, rch = 2 * node + 1, m = (s + e) / 2;
        ll x = query(lch, s, m, l, r), y = query(rch, m + 1, e, l, r);
        return min(x, y);
    }
};
ll M, N;
struct Rect{
    ll x1, y1, x2, y2, c;
    bool operator<(const Rect &r)const{
        return x1 < r.x1;
    }
};
ll P, B;
Rect A[400005];
 
int main(){
    cin.tie(0) -> sync_with_stdio(false);
 
    cin >> M >> N >> B >> P;
    for(int i = 1; i <= P; i++){
        cin >> A[i].x1 >> A[i].y1 >> A[i].x2 >> A[i].y2 >> A[i].c;
    }
    LazySegTree LST;
    ll L = 1, R = min(M, N);
    while(L <= R){
        ll K = (L + R) / 2; // rect K * K
        vector<ll> Y;
        vector<Rect> T;
        ll ans = 1e15;
        for(int i = 1; i <= P; i++){
            T.push_back({A[i].x1 - K + 1, A[i].y1 - K + 1, A[i].x1 - K + 1, A[i].y2, A[i].c});
            T.push_back({A[i].x2, A[i].y1 - K + 1, A[i].x2, A[i].y2, -A[i].c});
        }
        for(int i = 0; i < T.size(); i++){
            T[i].y1 = max(T[i].y1, 1LL);
            T[i].y2 = min(T[i].y2, N);
        }
        sort(T.begin(), T.end());
        ll last = 0;
        for(int i = 1; i <= M - K + 1; i++){
            while(last < T.size() && T[last].x1 <= i){
                LST.update(T[last].y1, T[last].y2, T[last].c);
                last++;
            }
            ans = min(ans, LST.query(1, N - K + 1));
        }
        while(last < T.size()){
            LST.update(T[last].y1, T[last].y2, T[last].c);
            last++;
        }
        if(ans <= B){
            L = K + 1;
        } else {
            R = K - 1;
        }
    }
    cout << max(0LL, L - 1);
}

Compilation message

pyramid_base.cpp: In function 'int main()':
pyramid_base.cpp:70:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<Rect>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   70 |         for(int i = 0; i < T.size(); i++){
      |                        ~~^~~~~~~~~~
pyramid_base.cpp:77:24: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<Rect>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   77 |             while(last < T.size() && T[last].x1 <= i){
      |                   ~~~~~^~~~~~~~~~
pyramid_base.cpp:83:20: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<Rect>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   83 |         while(last < T.size()){
      |               ~~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 33 ms 65852 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 33 ms 65868 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 36 ms 66008 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 60 ms 66124 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 223 ms 66160 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 579 ms 66260 KB Output is correct
2 Incorrect 2548 ms 66332 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2223 ms 66332 KB Output is correct
2 Correct 847 ms 66164 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 97 ms 67232 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 508 ms 69060 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1679 ms 70936 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2467 ms 71584 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1882 ms 72152 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 5095 ms 110048 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 5077 ms 139296 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 5079 ms 143256 KB Time limit exceeded
2 Halted 0 ms 0 KB -