Submission #220816

# Submission time Handle Problem Language Result Execution time Memory
220816 2020-04-09T00:49:59 Z qkxwsm Pyramid Base (IOI08_pyramid_base) C++14
35 / 100
5000 ms 116948 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)
{
    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
    FOR(i, 0, N)
    {
        ins[i].clear();
        del[i].clear();
    }
    FOR(i, 0, K)
    {
        pii p = {max(0, arr[i].y1 - x + 1), arr[i].y2};
        ins[max(0, arr[i].x1 - x + 1)].PB(p);
        del[arr[i].x2].PB(p);
    }
    int sz = M - x; sz = (1 << (33 - __builtin_clz(sz)));
    fill(seg, seg + sz + 1, 0);
    fill(lazy, lazy + sz + 1, 0);
    // cerr << "TEST " << x << endl;
    FOR(i, 0, N - x + 1)
    {
        // cerr << "pos " << i << endl;
        for (auto p : ins[i])
        {
            update(1, 0, M - x, p.fi, p.se, 1);
            // cerr << "+1 " << p.fi << ',' << p.se << endl;
        }
        // cerr << "seg1 " << seg[1] << endl;
        if (seg[1] == 0) return true;
        for (auto p : del[i])
        {
            update(1, 0, M - x, p.fi, p.se, -1);
            // cerr << "-1 " << p.fi << ',' << p.se << endl;
        }
    }
    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)
    {
        cin >> arr[i].x1 >> arr[i].y1 >> arr[i].x2 >> arr[i].y2 >> arr[i].cost;
        arr[i].x1--; arr[i].y1--; arr[i].x2--; arr[i].y2--;
    }
    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 36 ms 53376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 37 ms 53496 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 38 ms 53504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 42 ms 53888 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 64 ms 55872 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 159 ms 61920 KB Output is correct
2 Correct 282 ms 70392 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 302 ms 70504 KB Output is correct
2 Correct 177 ms 61816 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 85 ms 54264 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 314 ms 59256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1090 ms 80656 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1124 ms 82936 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1439 ms 85088 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 5071 ms 109204 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 5064 ms 114588 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 5076 ms 116948 KB Time limit exceeded
2 Halted 0 ms 0 KB -