답안 #547716

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
547716 2022-04-11T14:21:16 Z alexxela12345 Pyramid Base (IOI08_pyramid_base) C++17
70 / 100
5000 ms 98376 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 int 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;

int tree[4 * MAXN];
int 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);
}

int 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));
}

int 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(0LL, obstacles[i].x1 - r + 1), max(0LL, obstacles[i].y1 - r + 1), obstacles[i].y2, obstacles[i].cost});
        qq.push_back({obstacles[i].x2, max(0LL, 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();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 1108 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 4564 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 30 ms 16488 KB Output is correct
2 Correct 53 ms 31308 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 60 ms 31628 KB Output is correct
2 Correct 40 ms 17724 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 57 ms 2012 KB Output is correct
2 Correct 90 ms 2024 KB Output is correct
3 Correct 71 ms 2008 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 393 ms 7440 KB Output is correct
2 Correct 439 ms 7444 KB Output is correct
3 Correct 393 ms 7368 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 792 ms 37860 KB Output is correct
2 Correct 106 ms 4868 KB Output is correct
3 Correct 330 ms 37692 KB Output is correct
4 Correct 999 ms 38080 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1174 ms 38588 KB Output is correct
2 Correct 1076 ms 38564 KB Output is correct
3 Correct 721 ms 38536 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1069 ms 38996 KB Output is correct
2 Correct 1462 ms 38348 KB Output is correct
3 Correct 1449 ms 38456 KB Output is correct
4 Correct 1435 ms 38412 KB Output is correct
5 Correct 1439 ms 38400 KB Output is correct
6 Correct 816 ms 38280 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 5064 ms 70296 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 5072 ms 94308 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 5058 ms 98376 KB Time limit exceeded
2 Halted 0 ms 0 KB -