Submission #547719

# Submission time Handle Problem Language Result Execution time Memory
547719 2022-04-11T14:23:16 Z alexxela12345 Pyramid Base (IOI08_pyramid_base) C++17
70 / 100
5000 ms 70132 KB
#pragma GCC optimize("Ofast,unroll-loops,fast-math,inline,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.1,sse4.2,avx,avx2,abm,mmx,popcnt")
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ldb;

//#define int ll

const ll INF = 1e18 + 228;

struct obstacle {
    int x1, y1, x2, y2, cost;
};

int n, m;
int p;
int q;
vector<obstacle> obstacles;

const int MAXN = 1e6 + 228;

ll tree[4 * MAXN];
ll mod[4 * MAXN];

void push(int v, int l, int r) {
    tree[v] += mod[v];
    if (l + 1 != r) {
        mod[2 * v + 1] += mod[v];
        mod[2 * v + 2] += mod[v];   
    }
    mod[v] = 0;
}

void add(int v, int l, int r, int ql, int qr, int val) {
    push(v, l, r);
    if (l >= qr || ql >= r) {
        return;
    }
    if (ql <= l && r <= qr) {
        mod[v] += val;
        push(v, l, r);
        return;
    }
    int m = (l + r) / 2;
    add(2 * v + 1, l, m, ql, qr, val);
    add(2 * v + 2, m, r, ql, qr, val);
    tree[v] = min(tree[2 * v + 1], tree[2 * v + 2]);
}

void add(int l, int r, int val) {
    add(0, 0, m, l, r, val);
}

ll get(int v, int l, int r, int ql, int qr) {
    push(v, l, r);
    if (l >= qr || ql >= r) {
        return INF;
    }
    if (ql <= l && r <= qr) {
        return tree[v];
    }
    int m = (l + r) / 2;
    return min(get(2 * v + 1, l, m, ql, qr), get(2 * v + 2, m, r, ql, qr));
}

ll get_mn(int l, int r) {
    return get(0, 0, m, l, r);
}

bool canBuild(int r) {
    vector<array<int, 4>> qq; // {time, l, r, val}
    for (int i = 0; i < q; i++) {
        qq.push_back({max(0, obstacles[i].x1 - r + 1), max(0, obstacles[i].y1 - r + 1), obstacles[i].y2, obstacles[i].cost});
        qq.push_back({obstacles[i].x2, max(0, obstacles[i].y1 - r + 1), obstacles[i].y2, -obstacles[i].cost});
    }
    qq.push_back({0, 0, m, 0});
    qq.push_back({n, 0, m, 0});
    sort(qq.begin(), qq.end());
    int last_time = 0;
    bool ans = 0;
    for (auto el : qq) {
        if (el[0] != last_time && last_time + r <= n) {
            int el = get_mn(0, m - r + 1);
            if (el <= p) {
                ans = 1;
            }
        }
        last_time = el[0];
        add(el[1], el[2], el[3]);
    }
    return ans;
}

void solve() {
    cin >> n >> m >> p >> q;
    obstacles.resize(q);
    for (int i = 0; i <q; i++) {
        cin >> obstacles[i].x1;
        cin >> obstacles[i].y1;
        cin >> obstacles[i].x2;
        cin >> obstacles[i].y2;
        cin >> obstacles[i].cost;
        obstacles[i].x1--;
        obstacles[i].y1--;
    }
    int L = 0;
    int R = min(n, m) + 1;
    while (R - L > 1) {
        int M = (L + R) / 2;
        if (canBuild(M)) {
            L = M;
        } else {
            R = M;
        }
    }
    cout << L << endl;
}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    solve();
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 412 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 928 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 27 ms 4456 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 32 ms 16448 KB Output is correct
2 Correct 58 ms 31276 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 72 ms 31464 KB Output is correct
2 Correct 34 ms 17664 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 66 ms 1616 KB Output is correct
2 Correct 87 ms 1380 KB Output is correct
3 Correct 78 ms 1400 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 514 ms 5716 KB Output is correct
2 Correct 435 ms 5720 KB Output is correct
3 Correct 405 ms 5784 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 836 ms 35244 KB Output is correct
2 Correct 107 ms 2408 KB Output is correct
3 Correct 351 ms 35208 KB Output is correct
4 Correct 1060 ms 35336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1140 ms 35600 KB Output is correct
2 Correct 1193 ms 35516 KB Output is correct
3 Correct 778 ms 35508 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1111 ms 35832 KB Output is correct
2 Correct 1631 ms 35808 KB Output is correct
3 Correct 1535 ms 35960 KB Output is correct
4 Correct 1507 ms 35904 KB Output is correct
5 Correct 1527 ms 35904 KB Output is correct
6 Correct 865 ms 35836 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 5060 ms 51652 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 5089 ms 64852 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 5069 ms 70132 KB Time limit exceeded
2 Halted 0 ms 0 KB -