# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1068020 |
2024-08-21T06:43:37 Z |
Gromp15 |
Rectangles (IOI19_rect) |
C++17 |
|
1606 ms |
73468 KB |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("avx2")
#include "rect.h"
#define ll long long
#define ar array
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using namespace std;
template<typename T> bool ckmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> bool ckmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define rint(l, r) uniform_int_distribution<int>(l, r)(rng)
struct fenwick {
int n; vector<int> bit;
fenwick(int a) : n(a), bit(a+1) {}
void update(int pos, int x) {
pos++;
for (int i = pos; i <= n; i += i&-i) bit[i] += x;
}
int sum(int pos) {
int res = 0;
while (pos) res += bit[pos], pos -= pos&-pos;
return res;
}
int query(int l, int r) {
return sum(r+1) - sum(l);
}
};
long long count_rectangles(std::vector<std::vector<int>> a) {
int n = sz(a), m = sz(a[0]);
if ((n <= 700 && m <= 700) || (n <= 3)) {
vector ok(n, vector(n, vector<bool>(m)));
for (int i = 0; i < m; i++) {
for (int j = 1; j < n-1; j++) {
int mx = 0;
for (int k = j; k < n-1; k++) {
ckmax(mx, a[k][i]);
ok[j][k][i] = mx >= min(a[j-1][i], a[k+1][i]);
}
}
}
vector<vector<int>> right(n, vector<int>(m, -1)), left(n, vector<int>(m, m-1));
for (int i = 0; i < n; i++) {
for (int j = 1; j < m-1; j++) {
int mx = 0;
for (int k = j; k < m-1; k++) {
ckmax(mx, a[i][k]);
if (mx >= a[i][j-1]) break;
right[i][j] = k;
}
}
for (int j = m-2; j >= 1; j--) {
int mx = 0;
for (int k = j; k >= 1; k--) {
ckmax(mx, a[i][k]);
if (mx >= a[i][j+1]) break;
left[i][j] = k;
}
}
}
long long ans = 0;
for (int i = 1; i < n-1; i++) {
vector<int> R(m, m-2), L(m, -1);
for (int j = i; j < n-1; j++) {
for (int k = 0; k < m; k++) {
ckmin(R[k], right[j][k]);
ckmax(L[k], left[j][k]);
}
vector<int> to(m, -1);
for (int k = m-1; k >= 0; k--) if (!ok[i][j][k]) {
int l = k;
while (l && !ok[i][j][l-1]) l--;
for (int z = l; z <= k; z++) to[z] = k;
k = l;
}
for (int k = 1; k < m-1; k++) {
int r = min(to[k], R[k]);
for (int l = k; l <= r; l++) ans += L[l] <= k;
}
}
}
return ans;
}
vector<vector<int>> to(n, vector<int>(m));
for (int i = 1; i < m-1; i++) {
for (int j = n-2; j > 0; j--) if (!a[j][i]) {
int l = j;
while (l-1 > 0 && !a[l-1][i]) l--;
for (int k = l; k <= j; k++) to[k][i] = j;
j = l;
}
}
int ans = 0;
for (int i = 0; i < n; i++) {
vector<int> l(m), r(m, m-1);
vector<int> st;
for (int j = 0; j < m; j++) {
while (st.size() && to[i][st.back()] >= to[i][j]) st.pop_back();
if (st.size()) l[j] = st.back();
st.emplace_back(j);
}
st.clear();
for (int j = m-1; j >= 0; j--) {
while (st.size() && to[i][st.back()] >= to[i][j]) st.pop_back();
if (st.size()) r[j] = st.back();
st.emplace_back(j);
}
for (int j = 0; j < m-1; j++) if (l[j] <= j && j <= r[j]) {
ckmax(ans, (to[i][j] - i + 1) * (r[j] - l[j] - 1));
}
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
344 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
344 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
2 ms |
860 KB |
Output is correct |
23 |
Correct |
2 ms |
860 KB |
Output is correct |
24 |
Correct |
2 ms |
860 KB |
Output is correct |
25 |
Correct |
3 ms |
860 KB |
Output is correct |
26 |
Correct |
2 ms |
860 KB |
Output is correct |
27 |
Correct |
3 ms |
860 KB |
Output is correct |
28 |
Correct |
3 ms |
860 KB |
Output is correct |
29 |
Correct |
2 ms |
856 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
344 KB |
Output is correct |
17 |
Correct |
2 ms |
860 KB |
Output is correct |
18 |
Correct |
2 ms |
860 KB |
Output is correct |
19 |
Correct |
2 ms |
860 KB |
Output is correct |
20 |
Correct |
3 ms |
860 KB |
Output is correct |
21 |
Correct |
2 ms |
860 KB |
Output is correct |
22 |
Correct |
3 ms |
860 KB |
Output is correct |
23 |
Correct |
3 ms |
860 KB |
Output is correct |
24 |
Correct |
2 ms |
856 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
0 ms |
348 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
28 ms |
4488 KB |
Output is correct |
31 |
Correct |
30 ms |
4444 KB |
Output is correct |
32 |
Correct |
28 ms |
4444 KB |
Output is correct |
33 |
Correct |
24 ms |
4488 KB |
Output is correct |
34 |
Correct |
25 ms |
4488 KB |
Output is correct |
35 |
Correct |
25 ms |
4444 KB |
Output is correct |
36 |
Correct |
25 ms |
4488 KB |
Output is correct |
37 |
Correct |
27 ms |
4440 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
344 KB |
Output is correct |
17 |
Correct |
2 ms |
860 KB |
Output is correct |
18 |
Correct |
2 ms |
860 KB |
Output is correct |
19 |
Correct |
2 ms |
860 KB |
Output is correct |
20 |
Correct |
3 ms |
860 KB |
Output is correct |
21 |
Correct |
2 ms |
860 KB |
Output is correct |
22 |
Correct |
3 ms |
860 KB |
Output is correct |
23 |
Correct |
3 ms |
860 KB |
Output is correct |
24 |
Correct |
2 ms |
856 KB |
Output is correct |
25 |
Correct |
28 ms |
4488 KB |
Output is correct |
26 |
Correct |
30 ms |
4444 KB |
Output is correct |
27 |
Correct |
28 ms |
4444 KB |
Output is correct |
28 |
Correct |
24 ms |
4488 KB |
Output is correct |
29 |
Correct |
25 ms |
4488 KB |
Output is correct |
30 |
Correct |
25 ms |
4444 KB |
Output is correct |
31 |
Correct |
25 ms |
4488 KB |
Output is correct |
32 |
Correct |
27 ms |
4440 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
1 ms |
348 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
36 |
Correct |
0 ms |
348 KB |
Output is correct |
37 |
Correct |
0 ms |
348 KB |
Output is correct |
38 |
Correct |
1606 ms |
73208 KB |
Output is correct |
39 |
Correct |
1572 ms |
73304 KB |
Output is correct |
40 |
Correct |
1545 ms |
73300 KB |
Output is correct |
41 |
Correct |
1522 ms |
73300 KB |
Output is correct |
42 |
Correct |
1493 ms |
73296 KB |
Output is correct |
43 |
Correct |
1600 ms |
73280 KB |
Output is correct |
44 |
Correct |
1597 ms |
73208 KB |
Output is correct |
45 |
Correct |
1320 ms |
64592 KB |
Output is correct |
46 |
Correct |
1464 ms |
73300 KB |
Output is correct |
47 |
Correct |
1440 ms |
73204 KB |
Output is correct |
48 |
Correct |
1418 ms |
73212 KB |
Output is correct |
49 |
Correct |
1429 ms |
73468 KB |
Output is correct |
50 |
Correct |
551 ms |
54152 KB |
Output is correct |
51 |
Correct |
284 ms |
20560 KB |
Output is correct |
52 |
Correct |
1382 ms |
73296 KB |
Output is correct |
53 |
Correct |
1450 ms |
73280 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
348 KB |
Output is correct |
2 |
Correct |
6 ms |
544 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
380 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Incorrect |
111 ms |
34184 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
344 KB |
Output is correct |
17 |
Correct |
2 ms |
860 KB |
Output is correct |
18 |
Correct |
2 ms |
860 KB |
Output is correct |
19 |
Correct |
2 ms |
860 KB |
Output is correct |
20 |
Correct |
3 ms |
860 KB |
Output is correct |
21 |
Correct |
2 ms |
860 KB |
Output is correct |
22 |
Correct |
3 ms |
860 KB |
Output is correct |
23 |
Correct |
3 ms |
860 KB |
Output is correct |
24 |
Correct |
2 ms |
856 KB |
Output is correct |
25 |
Correct |
28 ms |
4488 KB |
Output is correct |
26 |
Correct |
30 ms |
4444 KB |
Output is correct |
27 |
Correct |
28 ms |
4444 KB |
Output is correct |
28 |
Correct |
24 ms |
4488 KB |
Output is correct |
29 |
Correct |
25 ms |
4488 KB |
Output is correct |
30 |
Correct |
25 ms |
4444 KB |
Output is correct |
31 |
Correct |
25 ms |
4488 KB |
Output is correct |
32 |
Correct |
27 ms |
4440 KB |
Output is correct |
33 |
Correct |
1606 ms |
73208 KB |
Output is correct |
34 |
Correct |
1572 ms |
73304 KB |
Output is correct |
35 |
Correct |
1545 ms |
73300 KB |
Output is correct |
36 |
Correct |
1522 ms |
73300 KB |
Output is correct |
37 |
Correct |
1493 ms |
73296 KB |
Output is correct |
38 |
Correct |
1600 ms |
73280 KB |
Output is correct |
39 |
Correct |
1597 ms |
73208 KB |
Output is correct |
40 |
Correct |
1320 ms |
64592 KB |
Output is correct |
41 |
Correct |
1464 ms |
73300 KB |
Output is correct |
42 |
Correct |
1440 ms |
73204 KB |
Output is correct |
43 |
Correct |
1418 ms |
73212 KB |
Output is correct |
44 |
Correct |
1429 ms |
73468 KB |
Output is correct |
45 |
Correct |
551 ms |
54152 KB |
Output is correct |
46 |
Correct |
284 ms |
20560 KB |
Output is correct |
47 |
Correct |
1382 ms |
73296 KB |
Output is correct |
48 |
Correct |
1450 ms |
73280 KB |
Output is correct |
49 |
Correct |
7 ms |
348 KB |
Output is correct |
50 |
Correct |
6 ms |
544 KB |
Output is correct |
51 |
Correct |
0 ms |
348 KB |
Output is correct |
52 |
Correct |
0 ms |
380 KB |
Output is correct |
53 |
Correct |
1 ms |
344 KB |
Output is correct |
54 |
Correct |
1 ms |
348 KB |
Output is correct |
55 |
Correct |
1 ms |
348 KB |
Output is correct |
56 |
Correct |
1 ms |
348 KB |
Output is correct |
57 |
Correct |
1 ms |
348 KB |
Output is correct |
58 |
Correct |
0 ms |
348 KB |
Output is correct |
59 |
Correct |
1 ms |
348 KB |
Output is correct |
60 |
Correct |
0 ms |
348 KB |
Output is correct |
61 |
Incorrect |
111 ms |
34184 KB |
Output isn't correct |
62 |
Halted |
0 ms |
0 KB |
- |