Submission #220823

# Submission time Handle Problem Language Result Execution time Memory
220823 2020-04-09T01:05:25 Z qkxwsm Pyramid Base (IOI08_pyramid_base) C++14
35 / 100
5000 ms 90872 KB
#include <bits/stdc++.h>

using namespace std;

template<class T, class U>
void ckmin(T &a, U b)
{
    if (a > b) a = b;
}

template<class T, class U>
void ckmax(T &a, U b)
{
    if (a < b) a = b;
}

#define y1 asdf
#define y2 asdfasd
#define MP make_pair
#define PB push_back
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
#define SZ(x) ((int) (x).size())
#define ALL(x) (x).begin(), (x).end()
#define FOR(i, a, b) for (auto i = (a); i < (b); i++)
#define FORD(i, a, b) for (auto i = (a) - 1; i >= (b); i--)

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpi;
typedef vector<pll> vpl;

const int MAXN = 1130013;

int N, M, K, B;

struct rect
{
    int cost;
    int x1, y1, x2, y2;
};
rect arr[MAXN];
vpi ins[MAXN], del[MAXN];
int seg[2 * MAXN], lazy[2 * MAXN];

void push(int w, int L, int R)
{
    if (lazy[w] == 0) return;
    seg[w] += lazy[w];
    if (L != R)
    {
        lazy[w << 1] += lazy[w];
        lazy[w << 1 | 1] += lazy[w];
    }
    lazy[w] = 0;
    return;
}
void update(int w, int L, int R, int a, int b, int v)
{
    // if (w == 1)
    // {
    //     cerr << a << ' ' << b << ' ' << v << endl;
    // }
    push(w, L, R);
    if (b < L || R < a) return;
    if (a <= L && R <= b)
    {
        lazy[w] += v;
        push(w, L, R);
        return;
    }
    int mid = (L + R) >> 1;
    update(w << 1, L, mid, a, b, v);
    update(w << 1 | 1, mid + 1, R, a, b, v);
    seg[w] = min(seg[w << 1], seg[w << 1 | 1]);
}

bool check(int x)
{
    //[ai...ai + x - 1][bi...bi + x - 1].
    //in a segment tree, store:
    //mins, dp[x][y] = longest lengths of mins
    //0...x - 2
    int sz = (1 << (33 - __builtin_clz(M - x + 1)));
    fill(seg, seg + sz + 1, 0);
    fill(lazy, lazy + sz + 1, 0);
    // cerr << "TEST " << x << endl;
    FOR(i, 0, x - 1)
    {
        for (auto p : ins[i])
        {
            update(1, 0, M - x, max(0, p.fi - x + 1), p.se, 1);
        }
    }
    FOR(i, 0, N - x + 1)
    {
        // cerr << "pos " << i << endl;
        for (auto p : ins[i + x - 1])
        {
            update(1, 0, M - x, max(0, p.fi - x + 1), p.se, 1);
        }
        if (seg[1] == 0) return true;
        for (auto p : del[i])
        {
            update(1, 0, M - x, max(0, p.fi - x + 1), p.se, -1);
        }
    }
    return false;
}

int32_t main()
{
    cout << fixed << setprecision(12);
    cerr << fixed << setprecision(4);
    ios_base::sync_with_stdio(false); cin.tie(0);
    cin >> N >> M >> B >> K;
    FOR(i, 0, K)
    {
        int x1, y1, x2, y2, cost;
        cin >> x1 >> y1 >> x2 >> y2 >> cost;
        x1--; y1--; x2--; y2--;
        ins[x1].PB({y1, y2});
        del[x2].PB({y1, y2});
        // cerr << "insert " << x1 << ' ' << x2 << ' ' << y1 << ' ' << y2 << endl;
    }
    int lo = 0, hi = min(N, M);
    while(hi > lo)
    {
        int mid = (hi + lo + 1) >> 1;
        if (check(mid)) lo = mid;
        else hi = mid - 1;
    }
    cout << lo << '\n';
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 38 ms 53368 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 36 ms 53376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 42 ms 53504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 41 ms 53760 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 61 ms 55648 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 101 ms 61696 KB Output is correct
2 Correct 190 ms 69880 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 194 ms 69888 KB Output is correct
2 Correct 124 ms 61816 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 79 ms 53884 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 273 ms 56412 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 812 ms 71032 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 888 ms 71544 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1108 ms 71800 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 5085 ms 81324 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 5075 ms 86136 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 5084 ms 90872 KB Time limit exceeded
2 Halted 0 ms 0 KB -