#pragma GCC optimize("Ofast","unroll-all-loops")
#include "rect.h"
#include <bits/stdc++.h>
using namespace std;
long long count_rectangles(vector<vector<int>> a){
int n = a.size();
int m = a[0].size();
long long ans = 0;
for(int i=0;i<m;i++) {
vector<int> maxi(n);
vector allowedranges(n,vector(n,0));
for(int j=i+1;j<m-1;j++) {
stack<pair<int,int>> s;
int last_voilater = -1;
for(int k=0;k<n;k++) {
maxi[k]=max(maxi[k],a[k][j]);
if(k!=0 and (maxi[k-1]>=a[k-1][i] or maxi[k-1]>=a[k-1][j+1]))last_voilater=k-1;
while(!s.empty() and s.top().first<a[k][j])s.pop();
if(s.empty()) {
s.emplace(a[k][j],k);
continue;
}
int l = s.top().second;l++;
s.emplace(a[k][j],k);
int r = s.top().second;r--;
if(r<l)continue;
allowedranges[l][r]++;
if(l<=last_voilater)continue;
if(allowedranges[l][r]==j-i)ans++;
}
while(!s.empty())s.pop();
last_voilater = n;
for(int k=n-1;k>=0;k--) {
if(k!=n-1 and (maxi[k+1]>=a[k+1][i] or maxi[k+1]>=a[k+1][j+1]))last_voilater=k+1;
while(!s.empty() and s.top().first<a[k][j])s.pop();
if(s.empty() or s.top().first==a[k][j]) {
s.emplace(a[k][j],k);
continue;
}
int r = s.top().second;r--;
s.emplace(a[k][j],k);
int l = s.top().second;l++;
if(r<l)continue;
allowedranges[l][r]++;
if(last_voilater<=r)continue;
if(allowedranges[l][r]==j-i)ans++;
}
}
}
return ans;
}
# |
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 |
0 ms |
428 KB |
Output is correct |
8 |
Correct |
0 ms |
344 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 |
12 |
Correct |
1 ms |
344 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 |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
344 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
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 |
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 |
0 ms |
428 KB |
Output is correct |
8 |
Correct |
0 ms |
344 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 |
12 |
Correct |
1 ms |
344 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 |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
344 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
6 ms |
348 KB |
Output is correct |
23 |
Correct |
4 ms |
348 KB |
Output is correct |
24 |
Correct |
5 ms |
344 KB |
Output is correct |
25 |
Correct |
6 ms |
348 KB |
Output is correct |
26 |
Correct |
7 ms |
348 KB |
Output is correct |
27 |
Correct |
7 ms |
348 KB |
Output is correct |
28 |
Correct |
7 ms |
348 KB |
Output is correct |
29 |
Correct |
2 ms |
488 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 |
0 ms |
428 KB |
Output is correct |
8 |
Correct |
0 ms |
344 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 |
12 |
Correct |
1 ms |
344 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 |
348 KB |
Output is correct |
18 |
Correct |
4 ms |
348 KB |
Output is correct |
19 |
Correct |
5 ms |
344 KB |
Output is correct |
20 |
Correct |
6 ms |
348 KB |
Output is correct |
21 |
Correct |
7 ms |
348 KB |
Output is correct |
22 |
Correct |
7 ms |
348 KB |
Output is correct |
23 |
Correct |
7 ms |
348 KB |
Output is correct |
24 |
Correct |
2 ms |
488 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
27 |
Correct |
1 ms |
344 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
1 ms |
348 KB |
Output is correct |
30 |
Correct |
77 ms |
860 KB |
Output is correct |
31 |
Correct |
76 ms |
900 KB |
Output is correct |
32 |
Correct |
63 ms |
856 KB |
Output is correct |
33 |
Correct |
100 ms |
856 KB |
Output is correct |
34 |
Correct |
112 ms |
860 KB |
Output is correct |
35 |
Correct |
117 ms |
856 KB |
Output is correct |
36 |
Correct |
110 ms |
904 KB |
Output is correct |
37 |
Correct |
105 ms |
900 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 |
0 ms |
428 KB |
Output is correct |
8 |
Correct |
0 ms |
344 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 |
12 |
Correct |
1 ms |
344 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 |
348 KB |
Output is correct |
18 |
Correct |
4 ms |
348 KB |
Output is correct |
19 |
Correct |
5 ms |
344 KB |
Output is correct |
20 |
Correct |
6 ms |
348 KB |
Output is correct |
21 |
Correct |
7 ms |
348 KB |
Output is correct |
22 |
Correct |
7 ms |
348 KB |
Output is correct |
23 |
Correct |
7 ms |
348 KB |
Output is correct |
24 |
Correct |
2 ms |
488 KB |
Output is correct |
25 |
Correct |
77 ms |
860 KB |
Output is correct |
26 |
Correct |
76 ms |
900 KB |
Output is correct |
27 |
Correct |
63 ms |
856 KB |
Output is correct |
28 |
Correct |
100 ms |
856 KB |
Output is correct |
29 |
Correct |
112 ms |
860 KB |
Output is correct |
30 |
Correct |
117 ms |
856 KB |
Output is correct |
31 |
Correct |
110 ms |
904 KB |
Output is correct |
32 |
Correct |
105 ms |
900 KB |
Output is correct |
33 |
Correct |
1 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
1 ms |
344 KB |
Output is correct |
36 |
Correct |
0 ms |
348 KB |
Output is correct |
37 |
Correct |
1 ms |
348 KB |
Output is correct |
38 |
Correct |
3323 ms |
6248 KB |
Output is correct |
39 |
Correct |
2706 ms |
6252 KB |
Output is correct |
40 |
Correct |
2627 ms |
6232 KB |
Output is correct |
41 |
Correct |
2546 ms |
6232 KB |
Output is correct |
42 |
Correct |
3041 ms |
6260 KB |
Output is correct |
43 |
Correct |
2990 ms |
6216 KB |
Output is correct |
44 |
Correct |
2980 ms |
6256 KB |
Output is correct |
45 |
Correct |
3130 ms |
5912 KB |
Output is correct |
46 |
Correct |
3997 ms |
6232 KB |
Output is correct |
47 |
Correct |
4773 ms |
6392 KB |
Output is correct |
48 |
Execution timed out |
5054 ms |
6280 KB |
Time limit exceeded |
49 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
178 ms |
344 KB |
Output is correct |
2 |
Correct |
127 ms |
348 KB |
Output is correct |
3 |
Correct |
177 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
209 ms |
476 KB |
Output is correct |
6 |
Correct |
208 ms |
348 KB |
Output is correct |
7 |
Correct |
227 ms |
348 KB |
Output is correct |
8 |
Correct |
205 ms |
348 KB |
Output is correct |
9 |
Correct |
199 ms |
344 KB |
Output is correct |
10 |
Correct |
96 ms |
348 KB |
Output is correct |
11 |
Correct |
151 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Execution timed out |
5094 ms |
28924 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |
# |
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 |
0 ms |
428 KB |
Output is correct |
8 |
Correct |
0 ms |
344 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 |
12 |
Correct |
1 ms |
344 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 |
348 KB |
Output is correct |
18 |
Correct |
4 ms |
348 KB |
Output is correct |
19 |
Correct |
5 ms |
344 KB |
Output is correct |
20 |
Correct |
6 ms |
348 KB |
Output is correct |
21 |
Correct |
7 ms |
348 KB |
Output is correct |
22 |
Correct |
7 ms |
348 KB |
Output is correct |
23 |
Correct |
7 ms |
348 KB |
Output is correct |
24 |
Correct |
2 ms |
488 KB |
Output is correct |
25 |
Correct |
77 ms |
860 KB |
Output is correct |
26 |
Correct |
76 ms |
900 KB |
Output is correct |
27 |
Correct |
63 ms |
856 KB |
Output is correct |
28 |
Correct |
100 ms |
856 KB |
Output is correct |
29 |
Correct |
112 ms |
860 KB |
Output is correct |
30 |
Correct |
117 ms |
856 KB |
Output is correct |
31 |
Correct |
110 ms |
904 KB |
Output is correct |
32 |
Correct |
105 ms |
900 KB |
Output is correct |
33 |
Correct |
3323 ms |
6248 KB |
Output is correct |
34 |
Correct |
2706 ms |
6252 KB |
Output is correct |
35 |
Correct |
2627 ms |
6232 KB |
Output is correct |
36 |
Correct |
2546 ms |
6232 KB |
Output is correct |
37 |
Correct |
3041 ms |
6260 KB |
Output is correct |
38 |
Correct |
2990 ms |
6216 KB |
Output is correct |
39 |
Correct |
2980 ms |
6256 KB |
Output is correct |
40 |
Correct |
3130 ms |
5912 KB |
Output is correct |
41 |
Correct |
3997 ms |
6232 KB |
Output is correct |
42 |
Correct |
4773 ms |
6392 KB |
Output is correct |
43 |
Execution timed out |
5054 ms |
6280 KB |
Time limit exceeded |
44 |
Halted |
0 ms |
0 KB |
- |