답안 #279744

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
279744 2020-08-22T10:36:03 Z evpipis Pyramid Base (IOI08_pyramid_base) C++11
70 / 100
5000 ms 130848 KB
#include <bits/stdc++.h>
using namespace std;

#define pb push_back
typedef long long ll;

const int len = 1e6+4;
const ll inf = 1e16;
int cost[len], n, m, bud, q;
vector<int> buck[len];

struct rectangle{
    int x1, x2, y1, y2;
} rec[len];

struct{
    struct node{
        ll mn, lazy;

        node(ll mn_ = 0, ll lazy_ = 0){
            mn = mn_;
            lazy = lazy_;
        }
    } tree[4*len];

    void prop(int p, int l, int r){
        if (!tree[p].lazy) return;

        tree[p].mn += tree[p].lazy;
        if (l != r){
            tree[2*p].lazy += tree[p].lazy;
            tree[2*p+1].lazy += tree[p].lazy;
        }
        tree[p].lazy = 0;
    }

    void update(int p, int l, int r, int i, int j, int v){
        prop(p, l, r);

        if (i <= l && r <= j)
            return void(tree[p].lazy += v);

        int mid = (l+r)/2;
        if (i <= mid)
            update(2*p, l, mid, i, j, v);
        if (j >= mid+1)
            update(2*p+1, mid+1, r, i, j, v);

        prop(2*p, l, mid), prop(2*p+1, mid+1, r);
        tree[p].mn = min(tree[2*p].mn, tree[2*p+1].mn);
    }

    ll query(int p, int l, int r, int i, int j){
        prop(p, l, r);

        if (r < i || j < l)
            return inf;
        if (i <= l && r <= j)
            return tree[p].mn;

        int mid = (l+r)/2;
        return min(query(2*p, l, mid, i, j), query(2*p+1, mid+1, r, i, j));
    }
} seg_tree1;

bool check(int k){
    for (int i = 1; i <= q; i++){
        int y1 = rec[i].y1, y2 = rec[i].y2;

        buck[max(1, y1-k+1)].pb(i);
        buck[y2+1].pb(-i);
    }

    bool ans = false;
    for (int y = 1; y <= m+1; y++){
        int must = (y==1);
        for (int j = 0; j < buck[y].size(); j++){
            int i = abs(buck[y][j]);
            int x1 = rec[i].x1, x2 = rec[i].x2;

            if (buck[y][j] > 0)
                seg_tree1.update(1, 1, n, max(1, x1-k+1), x2, cost[i]);
            else
                must = 1, seg_tree1.update(1, 1, n, max(1, x1-k+1), x2, -cost[i]);
        }

        buck[y].clear();
        if (must && y <= m-k+1)
            ans |= (seg_tree1.query(1, 1, n, 1, n-k+1) <= bud);
    }

    return ans;
}

int solve1(){
    int l = 1, r = min(n, m), ans = 0;
    while (l <= r){
        int mid = (l+r)/2;
        if (check(mid))
            ans = mid, l = mid+1;
        else
            r = mid-1;
    }

    return ans;
}

int main(){
    scanf("%d %d %d %d", &n, &m, &bud, &q);
    for (int i = 1; i <= q; i++)
        scanf("%d %d %d %d %d", &rec[i].x1, &rec[i].y1, &rec[i].x2, &rec[i].y2, &cost[i]);

    printf("%d\n", solve1());
    return 0;
}

Compilation message

pyramid_base.cpp: In function 'bool check(int)':
pyramid_base.cpp:77:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   77 |         for (int j = 0; j < buck[y].size(); j++){
      |                         ~~^~~~~~~~~~~~~~~~
pyramid_base.cpp: In function 'int main()':
pyramid_base.cpp:109:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  109 |     scanf("%d %d %d %d", &n, &m, &bud, &q);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
pyramid_base.cpp:111:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  111 |         scanf("%d %d %d %d %d", &rec[i].x1, &rec[i].y1, &rec[i].x2, &rec[i].y2, &cost[i]);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 47 ms 86392 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 48 ms 86392 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 51 ms 86528 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 64 ms 86612 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 80 ms 86908 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 182 ms 86596 KB Output is correct
2 Correct 189 ms 86904 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 203 ms 87068 KB Output is correct
2 Correct 181 ms 86648 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 96 ms 86776 KB Output is correct
2 Correct 129 ms 87032 KB Output is correct
3 Correct 122 ms 87024 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 565 ms 89356 KB Output is correct
2 Correct 637 ms 89788 KB Output is correct
3 Correct 517 ms 89736 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1258 ms 92152 KB Output is correct
2 Correct 464 ms 87672 KB Output is correct
3 Correct 203 ms 91896 KB Output is correct
4 Correct 1568 ms 95864 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1701 ms 95096 KB Output is correct
2 Correct 1686 ms 97272 KB Output is correct
3 Correct 1208 ms 90360 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1704 ms 93304 KB Output is correct
2 Correct 2196 ms 100440 KB Output is correct
3 Correct 2161 ms 100200 KB Output is correct
4 Correct 2275 ms 100404 KB Output is correct
5 Correct 2218 ms 99840 KB Output is correct
6 Correct 1341 ms 89556 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 5084 ms 119744 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 5103 ms 125332 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 5099 ms 130848 KB Time limit exceeded
2 Halted 0 ms 0 KB -