# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1031019 |
2024-07-22T13:31:54 Z |
Zicrus |
Rectangles (IOI19_rect) |
C++17 |
|
5000 ms |
388580 KB |
#include <bits/stdc++.h>
#include "rect.h"
using namespace std;
typedef long long ll;
ll n, m;
ll pow2N, pow2M;
vector<vector<ll>> segN, segM;
ll segMaxN(ll low, ll high, ll m) {
low += pow2N; high += pow2N;
ll mx = 0;
while (low <= high) {
if (low & 1) mx = max(mx, segN[m][low++]);
if (!(high & 1)) mx = max(mx, segN[m][high--]);
low /= 2; high /= 2;
}
return mx;
}
ll segMaxM(ll low, ll high, ll n) {
low += pow2M; high += pow2M;
ll mx = 0;
while (low <= high) {
if (low & 1) mx = max(mx, segM[n][low++]);
if (!(high & 1)) mx = max(mx, segM[n][high--]);
low /= 2; high /= 2;
}
return mx;
}
ll count_rectangles(vector<vector<int>> a) {
if (a.size() <= 2) return 0;
n = a.size(); m = a[0].size();
pow2N = 1ll << (ll)ceil(log2(n));
pow2M = 1ll << (ll)ceil(log2(m));
vector<int> am = a[1];
segN = vector<vector<ll>>(m, vector<ll>(2*pow2N));
segM = vector<vector<ll>>(n, vector<ll>(2*pow2M));
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
segN[j][pow2N+i] = a[i][j];
segM[i][pow2M+j] = a[i][j];
}
}
for (int meta = 0; meta < n; meta++) {
for (int i = pow2M-1; i > 0; i--) {
segM[meta][i] = max(segM[meta][2*i], segM[meta][2*i+1]);
}
}
for (int meta = 0; meta < m; meta++) {
for (int i = pow2N-1; i > 0; i--) {
segN[meta][i] = max(segN[meta][2*i], segN[meta][2*i+1]);
}
}
unordered_set<ll> s;
ll res = 0;
for (int i = 1; i < n-1; i++) {
for (int j = 1; j < m-1; j++) {
ll left = j, right = j, top = i, bottom = i;
ll ref = a[i][j];
ll low = 0, high = j;
while (low < high) {
ll mid = (low + high + 1) / 2;
if (segMaxM(mid, high, i) <= ref) {
high = mid-1;
}
else {
low = mid;
}
}
left = low+1;
low = j, high = m-1;
while (low < high) {
ll mid = (low + high) / 2;
if (segMaxM(low, mid, i) <= ref) {
low = mid+1;
}
else {
high = mid;
}
}
right = high-1;
while (a[top][j] <= ref && top > 0) top--; top++;
while (a[bottom][j] <= ref && bottom < n-1) bottom++; bottom--;
ll hash = (left << 48) | (right << 32) | (top << 16) | bottom;
if (s.count(hash)) continue;
s.insert(hash);
ll lN = bottom-top+1, lM = right-left+1;
bool poss = 1;
for (int meta = top; meta < top+lN && poss; meta++) {
ll border = min(a[meta][left-1], a[meta][left+lM]);
if (border <= segMaxM(left, left+lM-1, meta)) {
poss = 0;
}
}
for (int meta = left; meta < left+lM && poss; meta++) {
ll border = min(a[top-1][meta], a[top+lN][meta]);
if (border <= segMaxN(top, top+lN-1, meta)) {
poss = 0;
}
}
res += poss;
}
}
return res;
}
Compilation message
rect.cpp: In function 'll count_rectangles(std::vector<std::vector<int> >)':
rect.cpp:88:13: warning: this 'while' clause does not guard... [-Wmisleading-indentation]
88 | while (a[top][j] <= ref && top > 0) top--; top++;
| ^~~~~
rect.cpp:88:56: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'while'
88 | while (a[top][j] <= ref && top > 0) top--; top++;
| ^~~
rect.cpp:89:13: warning: this 'while' clause does not guard... [-Wmisleading-indentation]
89 | while (a[bottom][j] <= ref && bottom < n-1) bottom++; bottom--;
| ^~~~~
rect.cpp:89:67: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'while'
89 | while (a[bottom][j] <= ref && bottom < n-1) bottom++; bottom--;
| ^~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 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 |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 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 |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 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 |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 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 |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 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 |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 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 |
6 ms |
860 KB |
Output is correct |
23 |
Correct |
7 ms |
860 KB |
Output is correct |
24 |
Correct |
7 ms |
860 KB |
Output is correct |
25 |
Correct |
2 ms |
860 KB |
Output is correct |
26 |
Correct |
2 ms |
860 KB |
Output is correct |
27 |
Correct |
2 ms |
884 KB |
Output is correct |
28 |
Correct |
2 ms |
860 KB |
Output is correct |
29 |
Correct |
1 ms |
604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 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 |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 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 |
348 KB |
Output is correct |
17 |
Correct |
6 ms |
860 KB |
Output is correct |
18 |
Correct |
7 ms |
860 KB |
Output is correct |
19 |
Correct |
7 ms |
860 KB |
Output is correct |
20 |
Correct |
2 ms |
860 KB |
Output is correct |
21 |
Correct |
2 ms |
860 KB |
Output is correct |
22 |
Correct |
2 ms |
884 KB |
Output is correct |
23 |
Correct |
2 ms |
860 KB |
Output is correct |
24 |
Correct |
1 ms |
604 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
0 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 |
127 ms |
3812 KB |
Output is correct |
31 |
Correct |
120 ms |
3760 KB |
Output is correct |
32 |
Correct |
114 ms |
3756 KB |
Output is correct |
33 |
Correct |
14 ms |
3416 KB |
Output is correct |
34 |
Correct |
18 ms |
3768 KB |
Output is correct |
35 |
Correct |
15 ms |
3864 KB |
Output is correct |
36 |
Correct |
15 ms |
3576 KB |
Output is correct |
37 |
Correct |
15 ms |
3608 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 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 |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 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 |
348 KB |
Output is correct |
17 |
Correct |
6 ms |
860 KB |
Output is correct |
18 |
Correct |
7 ms |
860 KB |
Output is correct |
19 |
Correct |
7 ms |
860 KB |
Output is correct |
20 |
Correct |
2 ms |
860 KB |
Output is correct |
21 |
Correct |
2 ms |
860 KB |
Output is correct |
22 |
Correct |
2 ms |
884 KB |
Output is correct |
23 |
Correct |
2 ms |
860 KB |
Output is correct |
24 |
Correct |
1 ms |
604 KB |
Output is correct |
25 |
Correct |
127 ms |
3812 KB |
Output is correct |
26 |
Correct |
120 ms |
3760 KB |
Output is correct |
27 |
Correct |
114 ms |
3756 KB |
Output is correct |
28 |
Correct |
14 ms |
3416 KB |
Output is correct |
29 |
Correct |
18 ms |
3768 KB |
Output is correct |
30 |
Correct |
15 ms |
3864 KB |
Output is correct |
31 |
Correct |
15 ms |
3576 KB |
Output is correct |
32 |
Correct |
15 ms |
3608 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
0 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 |
438 ms |
47472 KB |
Output is correct |
39 |
Correct |
428 ms |
47436 KB |
Output is correct |
40 |
Correct |
464 ms |
47548 KB |
Output is correct |
41 |
Correct |
424 ms |
47548 KB |
Output is correct |
42 |
Execution timed out |
5059 ms |
32672 KB |
Time limit exceeded |
43 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
856 KB |
Output is correct |
2 |
Correct |
17 ms |
860 KB |
Output is correct |
3 |
Correct |
2 ms |
860 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
4 ms |
860 KB |
Output is correct |
6 |
Correct |
4 ms |
860 KB |
Output is correct |
7 |
Correct |
3 ms |
860 KB |
Output is correct |
8 |
Correct |
4 ms |
860 KB |
Output is correct |
9 |
Correct |
3 ms |
860 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 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 |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
4484 ms |
224372 KB |
Output is correct |
8 |
Execution timed out |
5044 ms |
388580 KB |
Time limit exceeded |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 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 |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 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 |
348 KB |
Output is correct |
17 |
Correct |
6 ms |
860 KB |
Output is correct |
18 |
Correct |
7 ms |
860 KB |
Output is correct |
19 |
Correct |
7 ms |
860 KB |
Output is correct |
20 |
Correct |
2 ms |
860 KB |
Output is correct |
21 |
Correct |
2 ms |
860 KB |
Output is correct |
22 |
Correct |
2 ms |
884 KB |
Output is correct |
23 |
Correct |
2 ms |
860 KB |
Output is correct |
24 |
Correct |
1 ms |
604 KB |
Output is correct |
25 |
Correct |
127 ms |
3812 KB |
Output is correct |
26 |
Correct |
120 ms |
3760 KB |
Output is correct |
27 |
Correct |
114 ms |
3756 KB |
Output is correct |
28 |
Correct |
14 ms |
3416 KB |
Output is correct |
29 |
Correct |
18 ms |
3768 KB |
Output is correct |
30 |
Correct |
15 ms |
3864 KB |
Output is correct |
31 |
Correct |
15 ms |
3576 KB |
Output is correct |
32 |
Correct |
15 ms |
3608 KB |
Output is correct |
33 |
Correct |
438 ms |
47472 KB |
Output is correct |
34 |
Correct |
428 ms |
47436 KB |
Output is correct |
35 |
Correct |
464 ms |
47548 KB |
Output is correct |
36 |
Correct |
424 ms |
47548 KB |
Output is correct |
37 |
Execution timed out |
5059 ms |
32672 KB |
Time limit exceeded |
38 |
Halted |
0 ms |
0 KB |
- |