답안 #197818

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
197818 2020-01-23T12:02:36 Z SamAnd Pyramid Base (IOI08_pyramid_base) C++17
70 / 100
5000 ms 92208 KB
#include <bits/stdc++.h>
using namespace std;
const int N = 1000006;
struct ban
{
    int x1, y1, x2, y2, b;
};

int n, m, b;
int q;
ban a[N];

vector<int> va[N], vh[N];

int t[N * 4];
int laz[N * 4];

void shi(int pos)
{
    if (laz[pos] == 0)
        return;
    t[pos * 2] += laz[pos];
    t[pos * 2 + 1] += laz[pos];
    laz[pos * 2] += laz[pos];
    laz[pos * 2 + 1] += laz[pos];
    laz[pos] = 0;
}

void bil(int tl, int tr, int pos)
{
    t[pos] = 0;
    laz[pos] = 0;
    if (tl == tr)
    {
        return;
    }
    int m = (tl + tr) / 2;
    bil(tl, m, pos * 2);
    bil(m + 1, tr, pos * 2 + 1);
}

void ubd(int tl, int tr, int l, int r, int y, int pos)
{
    if (l > r)
        return;
    if (tl == l && tr == r)
    {
        t[pos] += y;
        laz[pos] += y;
        return;
    }
    shi(pos);
    int m = (tl + tr) / 2;
    ubd(tl, m, l, min(m, r), y, pos * 2);
    ubd(m + 1, tr, max(m + 1, l), r, y, pos * 2 + 1);
    t[pos] = min(t[pos * 2], t[pos * 2 + 1]);
}

bool stg(int u)
{
    bil(1, m - u + 1, 1);
    for (int i = 1; i <= u; ++i)
    {
        for (int j = 0; j < va[i].size(); ++j)
        {
            int k = va[i][j];
            ubd(1, m - u + 1, max(a[k].y1 - u + 1, 1), min(a[k].y2, m - u + 1), min(a[k].b, b + 1), 1);
        }
    }
    if (t[1] <= b)
        return true;
    for (int i = 2; i <= n - u + 1; ++i)
    {
        for (int j = 0; j < va[i + u - 1].size(); ++j)
        {
            int k = va[i + u - 1][j];
            ubd(1, m - u + 1, max(a[k].y1 - u + 1, 1), min(a[k].y2, m - u + 1), min(a[k].b, b + 1), 1);
        }
        for (int j = 0; j < vh[i - 1].size(); ++j)
        {
            int k = vh[i - 1][j];
            ubd(1, m - u + 1, max(a[k].y1 - u + 1, 1), min(a[k].y2, m - u + 1), -min(a[k].b, b + 1), 1);
        }
        if (t[1] <= b)
            return true;
    }
    return false;
}

int main()
{
    #ifdef SOMETHING
    freopen("input.txt", "r", stdin);
    #endif // SOMETHING
    scanf("%d%d", &n, &m);
    scanf("%d", &b);
    scanf("%d", &q);
    for (int i = 1; i <= q; ++i)
        scanf("%d%d%d%d%d", &a[i].x1, &a[i].y1, &a[i].x2, &a[i].y2, &a[i].b);
    for (int i = 1; i <= q; ++i)
    {
        va[a[i].x1].push_back(i);
        vh[a[i].x2].push_back(i);
    }
    int l = 1, r = min(n, m);
    int ans = 0;
    while (l <= r)
    {
        int m = (l + r) / 2;
        if (stg(m))
        {
            ans = m;
            l = m + 1;
        }
        else
            r = m - 1;
    }
    printf("%d\n", ans);
    return 0;
}

Compilation message

pyramid_base.cpp: In function 'bool stg(int)':
pyramid_base.cpp:64:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int j = 0; j < va[i].size(); ++j)
                         ~~^~~~~~~~~~~~~~
pyramid_base.cpp:74:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int j = 0; j < va[i + u - 1].size(); ++j)
                         ~~^~~~~~~~~~~~~~~~~~~~~~
pyramid_base.cpp:79:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int j = 0; j < vh[i - 1].size(); ++j)
                         ~~^~~~~~~~~~~~~~~~~~
pyramid_base.cpp: In function 'int main()':
pyramid_base.cpp:95:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &n, &m);
     ~~~~~^~~~~~~~~~~~~~~~
pyramid_base.cpp:96:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &b);
     ~~~~~^~~~~~~~~~
pyramid_base.cpp:97:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &q);
     ~~~~~^~~~~~~~~~
pyramid_base.cpp:99:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d%d%d%d", &a[i].x1, &a[i].y1, &a[i].x2, &a[i].y2, &a[i].b);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 46 ms 47352 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 46 ms 47352 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 49 ms 47340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 50 ms 47568 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 74 ms 49468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 149 ms 55672 KB Output is correct
2 Correct 321 ms 63848 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 325 ms 63872 KB Output is correct
2 Correct 174 ms 55544 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 55 ms 47708 KB Output is correct
2 Correct 100 ms 47836 KB Output is correct
3 Correct 92 ms 47924 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 220 ms 50572 KB Output is correct
2 Correct 378 ms 50652 KB Output is correct
3 Correct 316 ms 50488 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 367 ms 57096 KB Output is correct
2 Correct 74 ms 48888 KB Output is correct
3 Correct 251 ms 64448 KB Output is correct
4 Correct 654 ms 65348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 654 ms 65756 KB Output is correct
2 Correct 1178 ms 65544 KB Output is correct
3 Correct 269 ms 57692 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 475 ms 57936 KB Output is correct
2 Correct 1472 ms 66256 KB Output is correct
3 Correct 1402 ms 66040 KB Output is correct
4 Correct 1762 ms 66040 KB Output is correct
5 Correct 1678 ms 66040 KB Output is correct
6 Correct 247 ms 57976 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 5008 ms 79100 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 5091 ms 85860 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 5025 ms 92208 KB Time limit exceeded
2 Halted 0 ms 0 KB -