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;
}
void solv1()
{
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);
}
struct ban1
{
int l, r, ans, e;
ban1(){}
ban1(int x, int e)
{
l = r = ans = x;
this->e = e;
}
};
int q1[N * 4];
ban1 t1[N * 4];
void bil1(int tl, int tr, int pos)
{
t1[pos] = ban1(tr - tl + 1, tr - tl + 1);
if (tl == tr)
return;
int m = (tl + tr) / 2;
bil1(tl, m, pos * 2);
bil1(m + 1, tr, pos * 2 + 1);
}
ban1 mer1(const ban1& l, const ban1& r)
{
ban1 res;
res.e = l.e + r.e;
if (l.l == l.e)
res.l = l.l + r.l;
else
res.l = l.l;
if (r.r == r.e)
res.r = r.r + l.r;
else
res.r = r.r;
res.ans = max(l.ans, r.ans);
res.ans = max(res.ans, l.r + r.l);
return res;
}
void ubd1(int tl, int tr, int l, int r, int y, int pos)
{
if (l > r)
return;
if (tl == l && tr == r)
{
q1[pos] += y;
if (!q1[pos])
{
if (tl == tr)
t1[pos] = ban1(1, 1);
else
t1[pos] = mer1(t1[pos * 2], t1[pos * 2 + 1]);
}
else
t1[pos] = ban1(0, (r - l + 1));
return;
}
int m = (tl + tr) / 2;
ubd1(tl, m, l, min(m, r), y, pos * 2);
ubd1(m + 1, tr, max(m + 1, l), r, y, pos * 2 + 1);
if (!q1[pos])
t1[pos] = mer1(t1[pos * 2], t1[pos * 2 + 1]);
else
t1[pos] = ban1(0, (tr - tl + 1));
}
void solv2()
{
int ans = 0;
bil1(1, m, 1);
int r = 0;
for (int l = 1; l <= m; ++l)
{
while (1)
{
if (r == n + 1)
break;
if (t1[1].ans < (r - l + 1))
break;
++r;
for (int j = 0; j < va[r].size(); ++j)
{
int k = va[r][j];
ubd1(1, m, a[k].y1, a[k].y2, 1, 1);
}
}
ans = max(ans, r - l);
for (int j = 0; j < vh[l].size(); ++j)
{
int k = vh[l][j];
ubd1(1, m, a[k].y1, a[k].y2, -1, 1);
}
}
printf("%d\n", ans);
}
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);
}
if (b > 0)
{
solv1();
return 0;
}
solv2();
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 'void solv2()':
pyramid_base.cpp:190:31: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int j = 0; j < va[r].size(); ++j)
~~^~~~~~~~~~~~~~
pyramid_base.cpp:197:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int j = 0; j < vh[l].size(); ++j)
~~^~~~~~~~~~~~~~
pyramid_base.cpp: In function 'int main()':
pyramid_base.cpp:211: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:212:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &b);
~~~~~^~~~~~~~~~
pyramid_base.cpp:213:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &q);
~~~~~^~~~~~~~~~
pyramid_base.cpp:215: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... |