This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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), a[k].b, 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), a[k].b, 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), -a[k].b, 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 (stderr)
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);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |