Submission #220813

# Submission time Handle Problem Language Result Execution time Memory
220813 2020-04-09T00:21:45 Z qkxwsm Pyramid Base (IOI08_pyramid_base) C++14
30 / 100
5000 ms 120548 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 + 1, 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 + 1, 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 37 ms 53504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 37 ms 53504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 39 ms 53504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 43 ms 53880 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 69 ms 56056 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 150 ms 61948 KB Output is correct
2 Incorrect 286 ms 70392 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 301 ms 70520 KB Output is correct
2 Correct 173 ms 61816 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 88 ms 54428 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 368 ms 59548 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1212 ms 81284 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1252 ms 83704 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1629 ms 85728 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 5067 ms 110748 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 5079 ms 119172 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 5083 ms 120548 KB Time limit exceeded
2 Halted 0 ms 0 KB -