# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1058986 |
2024-08-14T15:39:22 Z |
Tob |
Rectangles (IOI19_rect) |
C++14 |
|
2571 ms |
807248 KB |
#include <bits/stdc++.h>
#include "rect.h"
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define pb push_back
#define FIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
using namespace std;
typedef long long ll;
typedef pair <ll, ll> pii;
const int N = 2507;
int b[N][N][4], h[N][N], res[N*N];
struct tri {
int x, y, z, ix;
};
vector <tri> qu[N], qu2[N];
ll count_rectangles(vector <vector <int> > a) {
int n = a.size(), m = a[0].size();
for (int i = 0; i < n; i++) {
stack <int> st;
for (int j = 0; j < m; j++) {
while (!st.empty() && a[i][st.top()] <= a[i][j]) st.pop();
if (st.empty()) b[i][j][0] = -1;
else b[i][j][0] = st.top();
st.push(j);
}
while (!st.empty()) st.pop();
for (int j = m-1; j >= 0; j--) {
while (!st.empty() && a[i][st.top()] <= a[i][j]) st.pop();
if (st.empty()) b[i][j][1] = -1;
else b[i][j][1] = st.top();
st.push(j);
}
}
for (int j = 0; j < m; j++) {
stack <int> st;
for (int i = 0; i < n; i++) {
while (!st.empty() && a[st.top()][j] <= a[i][j]) st.pop();
if (st.empty()) b[i][j][2] = -1;
else b[i][j][2] = st.top();
st.push(i);
}
while (!st.empty()) st.pop();
for (int i = n-1; i >= 0; i--) {
while (!st.empty() && a[st.top()][j] <= a[i][j]) st.pop();
if (st.empty()) b[i][j][3] = -1;
else b[i][j][3] = st.top();
st.push(i);
}
}
auto good = [&](int x, int y, int o) {return b[x][y][2*o] != -1 && b[x][y][2*o+1] != -1;};
for (int i = 1; i < n-1; i++) {
for (int j = 1; j < m-1; j++) {
if (good(i, j, 0) && good(i, j, 1)) {
qu[b[i][j][3]-1].pb({b[i][j][0], b[i][j][1], b[i][j][2], i*m+j});
qu2[b[i][j][1]-1].pb({b[i][j][2], b[i][j][3], b[i][j][0], i*m+j});
}
}
}
int cnt = 0;
for (int i = 1; i < n-1; i++) {
for (int j = 1; j < m-1; j++) if (good(i-1, j, 0) && h[b[i-1][j][0]][b[i-1][j][1]] >= 0) h[b[i-1][j][0]][b[i-1][j][1]] *= -1;
for (int j = 1; j < m-1; j++) if (good(i, j, 0) && h[b[i][j][0]][b[i][j][1]] <= 0) h[b[i][j][0]][b[i][j][1]] = -h[b[i][j][0]][b[i][j][1]]+1;
for (int j = 1; j < m-1; j++) if (good(i-1, j, 0) && h[b[i-1][j][0]][b[i-1][j][1]] < 0) h[b[i-1][j][0]][b[i-1][j][1]] = 0;
for (auto x : qu[i]) {
if (i - x.z <= h[x.x][x.y]) res[x.ix]++;
}
}
memset(h, 0, sizeof h);
for (int j = 1; j < m-1; j++) {
for (int i = 1; i < n-1; i++) if (good(i, j-1, 1) && h[b[i][j-1][2]][b[i][j-1][3]] >= 0) h[b[i][j-1][2]][b[i][j-1][3]] *= -1;
for (int i = 1; i < n-1; i++) if (good(i, j, 1) && h[b[i][j][2]][b[i][j][3]] <= 0) h[b[i][j][2]][b[i][j][3]] = -h[b[i][j][2]][b[i][j][3]]+1;
for (int i = 1; i < n-1; i++) if (good(i, j-1, 1)) if (h[b[i][j-1][2]][b[i][j-1][3]] < 0) h[b[i][j-1][2]][b[i][j-1][3]] = 0;
for (auto x : qu2[j]) {
if (j - x.z <= h[x.x][x.y]) res[x.ix]++;
}
}
map <ll, int> ma;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (res[i*m+j] == 2) {
ll en = 0;
for (int k = 0; k < 4; k++) en = (en << 16) + b[i][j][k];
cnt += !ma[en];
ma[en] = 1;
}
}
}
return cnt;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
27228 KB |
Output is correct |
2 |
Correct |
3 ms |
27228 KB |
Output is correct |
3 |
Correct |
3 ms |
27228 KB |
Output is correct |
4 |
Correct |
3 ms |
27356 KB |
Output is correct |
5 |
Correct |
3 ms |
29276 KB |
Output is correct |
6 |
Correct |
3 ms |
27224 KB |
Output is correct |
7 |
Correct |
3 ms |
27228 KB |
Output is correct |
8 |
Correct |
3 ms |
27228 KB |
Output is correct |
9 |
Correct |
3 ms |
27228 KB |
Output is correct |
10 |
Correct |
3 ms |
27180 KB |
Output is correct |
11 |
Correct |
3 ms |
27228 KB |
Output is correct |
12 |
Correct |
3 ms |
27228 KB |
Output is correct |
13 |
Correct |
3 ms |
27224 KB |
Output is correct |
14 |
Correct |
3 ms |
29276 KB |
Output is correct |
15 |
Correct |
3 ms |
29276 KB |
Output is correct |
16 |
Correct |
2 ms |
25180 KB |
Output is correct |
17 |
Correct |
3 ms |
27228 KB |
Output is correct |
18 |
Correct |
2 ms |
27228 KB |
Output is correct |
19 |
Correct |
3 ms |
27228 KB |
Output is correct |
20 |
Correct |
3 ms |
29276 KB |
Output is correct |
21 |
Correct |
3 ms |
29276 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
27228 KB |
Output is correct |
2 |
Correct |
3 ms |
27228 KB |
Output is correct |
3 |
Correct |
3 ms |
27228 KB |
Output is correct |
4 |
Correct |
3 ms |
27356 KB |
Output is correct |
5 |
Correct |
3 ms |
29276 KB |
Output is correct |
6 |
Correct |
3 ms |
27224 KB |
Output is correct |
7 |
Correct |
3 ms |
27228 KB |
Output is correct |
8 |
Correct |
3 ms |
27228 KB |
Output is correct |
9 |
Correct |
3 ms |
27228 KB |
Output is correct |
10 |
Correct |
3 ms |
27180 KB |
Output is correct |
11 |
Correct |
3 ms |
27228 KB |
Output is correct |
12 |
Correct |
3 ms |
27228 KB |
Output is correct |
13 |
Correct |
3 ms |
27224 KB |
Output is correct |
14 |
Correct |
3 ms |
29276 KB |
Output is correct |
15 |
Correct |
3 ms |
29276 KB |
Output is correct |
16 |
Correct |
2 ms |
25180 KB |
Output is correct |
17 |
Correct |
3 ms |
27228 KB |
Output is correct |
18 |
Correct |
2 ms |
27228 KB |
Output is correct |
19 |
Correct |
3 ms |
27228 KB |
Output is correct |
20 |
Correct |
3 ms |
29276 KB |
Output is correct |
21 |
Correct |
3 ms |
29276 KB |
Output is correct |
22 |
Correct |
4 ms |
30044 KB |
Output is correct |
23 |
Correct |
4 ms |
30044 KB |
Output is correct |
24 |
Correct |
5 ms |
30040 KB |
Output is correct |
25 |
Correct |
4 ms |
29532 KB |
Output is correct |
26 |
Correct |
4 ms |
29788 KB |
Output is correct |
27 |
Correct |
5 ms |
29788 KB |
Output is correct |
28 |
Correct |
5 ms |
29788 KB |
Output is correct |
29 |
Correct |
4 ms |
29532 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
27228 KB |
Output is correct |
2 |
Correct |
3 ms |
27228 KB |
Output is correct |
3 |
Correct |
3 ms |
27228 KB |
Output is correct |
4 |
Correct |
3 ms |
27356 KB |
Output is correct |
5 |
Correct |
3 ms |
29276 KB |
Output is correct |
6 |
Correct |
3 ms |
27224 KB |
Output is correct |
7 |
Correct |
3 ms |
27228 KB |
Output is correct |
8 |
Correct |
3 ms |
27228 KB |
Output is correct |
9 |
Correct |
3 ms |
27228 KB |
Output is correct |
10 |
Correct |
3 ms |
27180 KB |
Output is correct |
11 |
Correct |
3 ms |
27228 KB |
Output is correct |
12 |
Correct |
3 ms |
27228 KB |
Output is correct |
13 |
Correct |
3 ms |
27224 KB |
Output is correct |
14 |
Correct |
3 ms |
29276 KB |
Output is correct |
15 |
Correct |
3 ms |
29276 KB |
Output is correct |
16 |
Correct |
2 ms |
25180 KB |
Output is correct |
17 |
Correct |
4 ms |
30044 KB |
Output is correct |
18 |
Correct |
4 ms |
30044 KB |
Output is correct |
19 |
Correct |
5 ms |
30040 KB |
Output is correct |
20 |
Correct |
4 ms |
29532 KB |
Output is correct |
21 |
Correct |
4 ms |
29788 KB |
Output is correct |
22 |
Correct |
5 ms |
29788 KB |
Output is correct |
23 |
Correct |
5 ms |
29788 KB |
Output is correct |
24 |
Correct |
4 ms |
29532 KB |
Output is correct |
25 |
Correct |
3 ms |
27228 KB |
Output is correct |
26 |
Correct |
2 ms |
27228 KB |
Output is correct |
27 |
Correct |
3 ms |
27228 KB |
Output is correct |
28 |
Correct |
3 ms |
29276 KB |
Output is correct |
29 |
Correct |
3 ms |
29276 KB |
Output is correct |
30 |
Correct |
13 ms |
39624 KB |
Output is correct |
31 |
Correct |
14 ms |
39740 KB |
Output is correct |
32 |
Correct |
12 ms |
39880 KB |
Output is correct |
33 |
Correct |
9 ms |
37208 KB |
Output is correct |
34 |
Correct |
11 ms |
38236 KB |
Output is correct |
35 |
Correct |
12 ms |
38456 KB |
Output is correct |
36 |
Correct |
12 ms |
38492 KB |
Output is correct |
37 |
Correct |
13 ms |
38488 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
27228 KB |
Output is correct |
2 |
Correct |
3 ms |
27228 KB |
Output is correct |
3 |
Correct |
3 ms |
27228 KB |
Output is correct |
4 |
Correct |
3 ms |
27356 KB |
Output is correct |
5 |
Correct |
3 ms |
29276 KB |
Output is correct |
6 |
Correct |
3 ms |
27224 KB |
Output is correct |
7 |
Correct |
3 ms |
27228 KB |
Output is correct |
8 |
Correct |
3 ms |
27228 KB |
Output is correct |
9 |
Correct |
3 ms |
27228 KB |
Output is correct |
10 |
Correct |
3 ms |
27180 KB |
Output is correct |
11 |
Correct |
3 ms |
27228 KB |
Output is correct |
12 |
Correct |
3 ms |
27228 KB |
Output is correct |
13 |
Correct |
3 ms |
27224 KB |
Output is correct |
14 |
Correct |
3 ms |
29276 KB |
Output is correct |
15 |
Correct |
3 ms |
29276 KB |
Output is correct |
16 |
Correct |
2 ms |
25180 KB |
Output is correct |
17 |
Correct |
4 ms |
30044 KB |
Output is correct |
18 |
Correct |
4 ms |
30044 KB |
Output is correct |
19 |
Correct |
5 ms |
30040 KB |
Output is correct |
20 |
Correct |
4 ms |
29532 KB |
Output is correct |
21 |
Correct |
4 ms |
29788 KB |
Output is correct |
22 |
Correct |
5 ms |
29788 KB |
Output is correct |
23 |
Correct |
5 ms |
29788 KB |
Output is correct |
24 |
Correct |
4 ms |
29532 KB |
Output is correct |
25 |
Correct |
13 ms |
39624 KB |
Output is correct |
26 |
Correct |
14 ms |
39740 KB |
Output is correct |
27 |
Correct |
12 ms |
39880 KB |
Output is correct |
28 |
Correct |
9 ms |
37208 KB |
Output is correct |
29 |
Correct |
11 ms |
38236 KB |
Output is correct |
30 |
Correct |
12 ms |
38456 KB |
Output is correct |
31 |
Correct |
12 ms |
38492 KB |
Output is correct |
32 |
Correct |
13 ms |
38488 KB |
Output is correct |
33 |
Correct |
3 ms |
27228 KB |
Output is correct |
34 |
Correct |
2 ms |
27228 KB |
Output is correct |
35 |
Correct |
3 ms |
27228 KB |
Output is correct |
36 |
Correct |
3 ms |
29276 KB |
Output is correct |
37 |
Correct |
3 ms |
29276 KB |
Output is correct |
38 |
Correct |
30 ms |
62800 KB |
Output is correct |
39 |
Correct |
31 ms |
62812 KB |
Output is correct |
40 |
Correct |
28 ms |
62820 KB |
Output is correct |
41 |
Correct |
29 ms |
62804 KB |
Output is correct |
42 |
Correct |
136 ms |
108436 KB |
Output is correct |
43 |
Correct |
130 ms |
108432 KB |
Output is correct |
44 |
Correct |
135 ms |
108676 KB |
Output is correct |
45 |
Correct |
135 ms |
103304 KB |
Output is correct |
46 |
Correct |
54 ms |
73296 KB |
Output is correct |
47 |
Correct |
69 ms |
75288 KB |
Output is correct |
48 |
Correct |
115 ms |
92496 KB |
Output is correct |
49 |
Correct |
124 ms |
94292 KB |
Output is correct |
50 |
Correct |
60 ms |
75856 KB |
Output is correct |
51 |
Correct |
68 ms |
61148 KB |
Output is correct |
52 |
Correct |
150 ms |
92108 KB |
Output is correct |
53 |
Correct |
141 ms |
93004 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
27480 KB |
Output is correct |
2 |
Correct |
9 ms |
27484 KB |
Output is correct |
3 |
Correct |
3 ms |
29276 KB |
Output is correct |
4 |
Correct |
2 ms |
27228 KB |
Output is correct |
5 |
Correct |
9 ms |
27248 KB |
Output is correct |
6 |
Correct |
10 ms |
27228 KB |
Output is correct |
7 |
Correct |
9 ms |
27228 KB |
Output is correct |
8 |
Correct |
9 ms |
27228 KB |
Output is correct |
9 |
Correct |
9 ms |
27228 KB |
Output is correct |
10 |
Correct |
3 ms |
27228 KB |
Output is correct |
11 |
Correct |
3 ms |
27228 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
27228 KB |
Output is correct |
2 |
Correct |
2 ms |
27228 KB |
Output is correct |
3 |
Correct |
3 ms |
27228 KB |
Output is correct |
4 |
Correct |
3 ms |
29276 KB |
Output is correct |
5 |
Correct |
3 ms |
29276 KB |
Output is correct |
6 |
Correct |
3 ms |
27228 KB |
Output is correct |
7 |
Correct |
322 ms |
177912 KB |
Output is correct |
8 |
Correct |
720 ms |
346968 KB |
Output is correct |
9 |
Correct |
737 ms |
348500 KB |
Output is correct |
10 |
Correct |
724 ms |
348504 KB |
Output is correct |
11 |
Correct |
107 ms |
105512 KB |
Output is correct |
12 |
Correct |
217 ms |
178312 KB |
Output is correct |
13 |
Correct |
239 ms |
181840 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
27228 KB |
Output is correct |
2 |
Correct |
3 ms |
27228 KB |
Output is correct |
3 |
Correct |
3 ms |
27228 KB |
Output is correct |
4 |
Correct |
3 ms |
27356 KB |
Output is correct |
5 |
Correct |
3 ms |
29276 KB |
Output is correct |
6 |
Correct |
3 ms |
27224 KB |
Output is correct |
7 |
Correct |
3 ms |
27228 KB |
Output is correct |
8 |
Correct |
3 ms |
27228 KB |
Output is correct |
9 |
Correct |
3 ms |
27228 KB |
Output is correct |
10 |
Correct |
3 ms |
27180 KB |
Output is correct |
11 |
Correct |
3 ms |
27228 KB |
Output is correct |
12 |
Correct |
3 ms |
27228 KB |
Output is correct |
13 |
Correct |
3 ms |
27224 KB |
Output is correct |
14 |
Correct |
3 ms |
29276 KB |
Output is correct |
15 |
Correct |
3 ms |
29276 KB |
Output is correct |
16 |
Correct |
2 ms |
25180 KB |
Output is correct |
17 |
Correct |
4 ms |
30044 KB |
Output is correct |
18 |
Correct |
4 ms |
30044 KB |
Output is correct |
19 |
Correct |
5 ms |
30040 KB |
Output is correct |
20 |
Correct |
4 ms |
29532 KB |
Output is correct |
21 |
Correct |
4 ms |
29788 KB |
Output is correct |
22 |
Correct |
5 ms |
29788 KB |
Output is correct |
23 |
Correct |
5 ms |
29788 KB |
Output is correct |
24 |
Correct |
4 ms |
29532 KB |
Output is correct |
25 |
Correct |
13 ms |
39624 KB |
Output is correct |
26 |
Correct |
14 ms |
39740 KB |
Output is correct |
27 |
Correct |
12 ms |
39880 KB |
Output is correct |
28 |
Correct |
9 ms |
37208 KB |
Output is correct |
29 |
Correct |
11 ms |
38236 KB |
Output is correct |
30 |
Correct |
12 ms |
38456 KB |
Output is correct |
31 |
Correct |
12 ms |
38492 KB |
Output is correct |
32 |
Correct |
13 ms |
38488 KB |
Output is correct |
33 |
Correct |
30 ms |
62800 KB |
Output is correct |
34 |
Correct |
31 ms |
62812 KB |
Output is correct |
35 |
Correct |
28 ms |
62820 KB |
Output is correct |
36 |
Correct |
29 ms |
62804 KB |
Output is correct |
37 |
Correct |
136 ms |
108436 KB |
Output is correct |
38 |
Correct |
130 ms |
108432 KB |
Output is correct |
39 |
Correct |
135 ms |
108676 KB |
Output is correct |
40 |
Correct |
135 ms |
103304 KB |
Output is correct |
41 |
Correct |
54 ms |
73296 KB |
Output is correct |
42 |
Correct |
69 ms |
75288 KB |
Output is correct |
43 |
Correct |
115 ms |
92496 KB |
Output is correct |
44 |
Correct |
124 ms |
94292 KB |
Output is correct |
45 |
Correct |
60 ms |
75856 KB |
Output is correct |
46 |
Correct |
68 ms |
61148 KB |
Output is correct |
47 |
Correct |
150 ms |
92108 KB |
Output is correct |
48 |
Correct |
141 ms |
93004 KB |
Output is correct |
49 |
Correct |
9 ms |
27480 KB |
Output is correct |
50 |
Correct |
9 ms |
27484 KB |
Output is correct |
51 |
Correct |
3 ms |
29276 KB |
Output is correct |
52 |
Correct |
2 ms |
27228 KB |
Output is correct |
53 |
Correct |
9 ms |
27248 KB |
Output is correct |
54 |
Correct |
10 ms |
27228 KB |
Output is correct |
55 |
Correct |
9 ms |
27228 KB |
Output is correct |
56 |
Correct |
9 ms |
27228 KB |
Output is correct |
57 |
Correct |
9 ms |
27228 KB |
Output is correct |
58 |
Correct |
3 ms |
27228 KB |
Output is correct |
59 |
Correct |
3 ms |
27228 KB |
Output is correct |
60 |
Correct |
3 ms |
27228 KB |
Output is correct |
61 |
Correct |
322 ms |
177912 KB |
Output is correct |
62 |
Correct |
720 ms |
346968 KB |
Output is correct |
63 |
Correct |
737 ms |
348500 KB |
Output is correct |
64 |
Correct |
724 ms |
348504 KB |
Output is correct |
65 |
Correct |
107 ms |
105512 KB |
Output is correct |
66 |
Correct |
217 ms |
178312 KB |
Output is correct |
67 |
Correct |
239 ms |
181840 KB |
Output is correct |
68 |
Correct |
3 ms |
27228 KB |
Output is correct |
69 |
Correct |
2 ms |
27228 KB |
Output is correct |
70 |
Correct |
3 ms |
27228 KB |
Output is correct |
71 |
Correct |
3 ms |
29276 KB |
Output is correct |
72 |
Correct |
3 ms |
29276 KB |
Output is correct |
73 |
Correct |
407 ms |
217960 KB |
Output is correct |
74 |
Correct |
396 ms |
217936 KB |
Output is correct |
75 |
Correct |
385 ms |
217896 KB |
Output is correct |
76 |
Correct |
377 ms |
218020 KB |
Output is correct |
77 |
Correct |
2544 ms |
807248 KB |
Output is correct |
78 |
Correct |
1129 ms |
355760 KB |
Output is correct |
79 |
Correct |
1307 ms |
410960 KB |
Output is correct |
80 |
Correct |
2045 ms |
577704 KB |
Output is correct |
81 |
Correct |
1136 ms |
363856 KB |
Output is correct |
82 |
Correct |
1625 ms |
489176 KB |
Output is correct |
83 |
Correct |
2078 ms |
591400 KB |
Output is correct |
84 |
Correct |
1192 ms |
360908 KB |
Output is correct |
85 |
Correct |
2287 ms |
580940 KB |
Output is correct |
86 |
Correct |
2187 ms |
563020 KB |
Output is correct |
87 |
Correct |
1503 ms |
526908 KB |
Output is correct |
88 |
Correct |
2380 ms |
782508 KB |
Output is correct |
89 |
Correct |
2571 ms |
782976 KB |
Output is correct |
90 |
Correct |
2500 ms |
782920 KB |
Output is correct |