답안 #1045692

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1045692 2024-08-06T06:58:51 Z Uasoni Pyramid Base (IOI08_pyramid_base) C++14
80 / 100
5000 ms 44940 KB
#pragma GCC optimize("O3", "unroll-loops")
#pragma GCC target("avx", "bmi", "bmi2", "lzcnt", "popcnt")

#include<bits/stdc++.h>
using namespace std;

const int maxn = 4e5+5, maxp = 1e6+5, inf = 1e9;
int n, m, p, b;
struct R {
    int x1, y1, x2, y2, c;
    R() { x1 = y1 = x2 = y2 = c = 0; }
} obs[maxn];

struct N {
    int v, l;
} stree[4*maxp];
void push(int i) {
    if(stree[i].l != 0) {
        stree[i<<1].v += stree[i].l; stree[i<<1|1].v += stree[i].l;
        stree[i<<1].l += stree[i].l; stree[i<<1|1].l += stree[i].l;
        stree[i].l = 0;
    }
}
void update(int lq, int rq, int val, int i = 1, int l = 1, int r = maxp) {
    if(lq <= l && r <= rq) {
        stree[i].v += val, stree[i].l += val;
        return;
    }
    push(i);
    int mid = (l+r)/2;
    if(lq <= mid) update(lq, rq, val, i<<1, l, mid);
    if(rq >= mid+1) update(lq, rq, val, i<<1|1, mid+1, r);
    stree[i].v = min(stree[i<<1].v, stree[i<<1|1].v);
}
int query(int lq, int rq, int i = 1, int l = 1, int r = maxp) {
    if(lq <= l && r <= rq) return stree[i].v;
    push(i);
    int mid = (l+r)/2, ret = inf;
    if(lq <= mid) ret = min(ret, query(lq, rq, i<<1, l, mid));
    if(rq >= mid+1) ret = min(ret, query(lq, rq, i<<1|1, mid+1, r));
    return ret;
}

struct E {
    int t, val, l, r;
    bool operator<(const E &o) const {
        return t < o.t;
    }
}; vector<E> evs;

bool check(int x) {
    bool ret = false;
    evs.clear();
    for(int i = 1; i <= p; i++) {
        evs.push_back({max(1, obs[i].x1-x+1), obs[i].c, max(1, obs[i].y1-x+1), obs[i].y2});
        evs.push_back({obs[i].x2+1, -obs[i].c, max(1, obs[i].y1-x+1), obs[i].y2});
    }
    sort(evs.begin(), evs.end());
    for(int i = 0; i < evs.size(); i++) {
        update(evs[i].l, evs[i].r, evs[i].val);
        if(i >= evs.size()-1 || evs[i].t != evs[i+1].t) {
            if(evs[i].t+x-1 <= m) ret |= (query(1, n-x+1) <= b);
        }
    }
    return ret;
}

int bsearch(int l, int r) {
    int ret = 0;
    while(l <= r) {
        int mid = (l+r)/2;
        if(check(mid)) l = mid+1, ret = mid;
        else r = mid-1;
    }
    return ret;
}

int main() {
    cin.tie(0)->sync_with_stdio(0);
    cin >> m >> n >> b >> p; // m columns, n rows
    int red = min(m, n);
    for(int i = 1; i <= p; i++) {
        cin >> obs[i].x1 >> obs[i].y1 >> obs[i].x2 >> obs[i].y2 >> obs[i].c;
        if(b == 0) red = min(red, max({obs[i].x1-1, obs[i].y1-1, m-obs[i].x2, n-obs[i].y2}));
    }
    cout << bsearch(1, red) << "\n";
}

Compilation message

pyramid_base.cpp: In function 'bool check(int)':
pyramid_base.cpp:59:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<E>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |     for(int i = 0; i < evs.size(); i++) {
      |                    ~~^~~~~~~~~~~~
pyramid_base.cpp:61:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<E>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   61 |         if(i >= evs.size()-1 || evs[i].t != evs[i+1].t) {
      |            ~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 10588 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8540 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 8652 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 10840 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 12236 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 21880 KB Output is correct
2 Correct 20 ms 24916 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 38 ms 24716 KB Output is correct
2 Correct 16 ms 20312 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 42 ms 9248 KB Output is correct
2 Correct 46 ms 13068 KB Output is correct
3 Correct 43 ms 9180 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 204 ms 11224 KB Output is correct
2 Correct 233 ms 14552 KB Output is correct
3 Correct 191 ms 18140 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 350 ms 26328 KB Output is correct
2 Correct 85 ms 13784 KB Output is correct
3 Correct 144 ms 26160 KB Output is correct
4 Correct 442 ms 26584 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 539 ms 26480 KB Output is correct
2 Correct 515 ms 26840 KB Output is correct
3 Correct 394 ms 26540 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 551 ms 26712 KB Output is correct
2 Correct 651 ms 26924 KB Output is correct
3 Correct 679 ms 27096 KB Output is correct
4 Correct 645 ms 26840 KB Output is correct
5 Correct 622 ms 26904 KB Output is correct
6 Correct 345 ms 26836 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3888 ms 35508 KB Output is correct
2 Correct 1809 ms 22468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 5015 ms 39596 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 5044 ms 44940 KB Time limit exceeded
2 Halted 0 ms 0 KB -