# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1047683 |
2024-08-07T14:59:57 Z |
vjudge1 |
Rectangles (IOI19_rect) |
C++17 |
|
5000 ms |
809636 KB |
#include "rect.h"
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3")
const int N = 2510;
int n,m;
vector<array<int, 2>> gdr[N][N];
vector<array<int, 2>> gdc[N][N];
struct Side {
int r1, r2, c1, c2;
};
int fen[N];
void upd(int at, int add) {
at++;
while(at) {
fen[at]+=add;
at-=at&(-at);
}
}
int qry(int at) {
at++;
int sum=0;
while(at<N) {
sum+=fen[at];
at+=at&(-at);
}
return sum;
}
vector<int> stk;
long long count_rectangles(std::vector<std::vector<int> > a) {
n = a.size();
m = a[0].size();
for(int i = 0;i<n;i++) {
stk.clear();
for(int j = 0;j<m;j++) {
while(stk.size() and a[i][stk.back()] < a[i][j]){
stk.pop_back();
}
if(stk.size()) {
gdr[i][j].push_back({stk.back(), 1});
}
stk.push_back(j);
}
stk.clear();
for(int j = m-1;j>=0;j--) {
while(stk.size() and a[i][stk.back()] < a[i][j])stk.pop_back();
if(stk.size()) {
if(a[i][j] != a[i][stk.back()]) {
gdr[i][stk.back()].push_back({j,1});
}
}
stk.push_back(j);
}
}
for(int i = 0;i<m;i++) {
stk.clear();
for(int j = 0;j<n;j++) {
while(stk.size() and a[stk.back()][i] < a[j][i]){
stk.pop_back();
}
if(stk.size()) {
gdc[j][i].push_back({stk.back(),1});
}
stk.push_back(j);
}
stk.clear();
for(int j = n-1;j>=0;j--) {
while(stk.size() and a[stk.back()][i] < a[j][i])stk.pop_back();
if(stk.size()) {
if(a[j][i] != a[stk.back()][i]) {
gdc[stk.back()][i].push_back({j, 1});
}
}
stk.push_back(j);
}
}
long long ans=0;
for(int i = 0;i<n;i++) {
for(int j = 0;j<m;j++) {
sort(gdr[i][j].begin(), gdr[i][j].end());
sort(gdc[i][j].begin(), gdc[i][j].end());
gdr[i][j].erase(unique(gdr[i][j].begin(), gdr[i][j].end()), gdr[i][j].end());
gdc[i][j].erase(unique(gdc[i][j].begin(), gdc[i][j].end()), gdc[i][j].end());
if(i) {
for(auto &[u, v]:gdr[i][j]) {
auto it = lower_bound(gdr[i-1][j].begin(), gdr[i-1][j].end(), array<int,2>{u, 0});
if(it!=gdr[i-1][j].end() and (*it)[0] == u) {
v+=(*it)[1];
}
}
}
if(j) {
for(auto &[u, v]:gdc[i][j]) {
auto it = lower_bound(gdc[i][j-1].begin(), gdc[i][j-1].end(), array<int,2>{u, 0});
if(it!=gdc[i][j-1].end() and (*it)[0] == u) {
v+=(*it)[1];
}
}
}
if(i and j) {
for(auto k:gdr[i-1][j]) {
if(k[0] +1 == j)continue;
for(auto k2:gdc[i][j-1]) {
if(k2[0] +1 == i)continue;
// cout << i << " " << j << " " << k[0] << " " << k2[0] << " " << k[1] << " " << k2[1] << endl;
if(k[0] >= j - k2[1]-1 and k2[0] >= i - k[1] - 1)ans++;
}
}
}
}
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
42 ms |
296272 KB |
Output is correct |
2 |
Correct |
41 ms |
296308 KB |
Output is correct |
3 |
Correct |
44 ms |
296272 KB |
Output is correct |
4 |
Correct |
45 ms |
296288 KB |
Output is correct |
5 |
Correct |
44 ms |
296276 KB |
Output is correct |
6 |
Correct |
44 ms |
296272 KB |
Output is correct |
7 |
Correct |
41 ms |
296276 KB |
Output is correct |
8 |
Correct |
40 ms |
296172 KB |
Output is correct |
9 |
Correct |
40 ms |
296272 KB |
Output is correct |
10 |
Correct |
40 ms |
296284 KB |
Output is correct |
11 |
Correct |
39 ms |
296272 KB |
Output is correct |
12 |
Correct |
40 ms |
296276 KB |
Output is correct |
13 |
Correct |
42 ms |
296280 KB |
Output is correct |
14 |
Correct |
40 ms |
296280 KB |
Output is correct |
15 |
Correct |
40 ms |
296308 KB |
Output is correct |
16 |
Correct |
39 ms |
296276 KB |
Output is correct |
17 |
Correct |
40 ms |
296276 KB |
Output is correct |
18 |
Correct |
41 ms |
296272 KB |
Output is correct |
19 |
Correct |
40 ms |
296272 KB |
Output is correct |
20 |
Correct |
44 ms |
296532 KB |
Output is correct |
21 |
Correct |
43 ms |
296236 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
42 ms |
296272 KB |
Output is correct |
2 |
Correct |
41 ms |
296308 KB |
Output is correct |
3 |
Correct |
44 ms |
296272 KB |
Output is correct |
4 |
Correct |
45 ms |
296288 KB |
Output is correct |
5 |
Correct |
44 ms |
296276 KB |
Output is correct |
6 |
Correct |
44 ms |
296272 KB |
Output is correct |
7 |
Correct |
41 ms |
296276 KB |
Output is correct |
8 |
Correct |
40 ms |
296172 KB |
Output is correct |
9 |
Correct |
40 ms |
296272 KB |
Output is correct |
10 |
Correct |
40 ms |
296284 KB |
Output is correct |
11 |
Correct |
39 ms |
296272 KB |
Output is correct |
12 |
Correct |
40 ms |
296276 KB |
Output is correct |
13 |
Correct |
42 ms |
296280 KB |
Output is correct |
14 |
Correct |
40 ms |
296280 KB |
Output is correct |
15 |
Correct |
40 ms |
296308 KB |
Output is correct |
16 |
Correct |
39 ms |
296276 KB |
Output is correct |
17 |
Correct |
40 ms |
296276 KB |
Output is correct |
18 |
Correct |
41 ms |
296272 KB |
Output is correct |
19 |
Correct |
40 ms |
296272 KB |
Output is correct |
20 |
Correct |
44 ms |
296532 KB |
Output is correct |
21 |
Correct |
43 ms |
296236 KB |
Output is correct |
22 |
Correct |
42 ms |
296784 KB |
Output is correct |
23 |
Correct |
42 ms |
296784 KB |
Output is correct |
24 |
Correct |
42 ms |
296732 KB |
Output is correct |
25 |
Correct |
42 ms |
296744 KB |
Output is correct |
26 |
Correct |
42 ms |
296788 KB |
Output is correct |
27 |
Correct |
42 ms |
296820 KB |
Output is correct |
28 |
Correct |
42 ms |
296748 KB |
Output is correct |
29 |
Correct |
40 ms |
296408 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
42 ms |
296272 KB |
Output is correct |
2 |
Correct |
41 ms |
296308 KB |
Output is correct |
3 |
Correct |
44 ms |
296272 KB |
Output is correct |
4 |
Correct |
45 ms |
296288 KB |
Output is correct |
5 |
Correct |
44 ms |
296276 KB |
Output is correct |
6 |
Correct |
44 ms |
296272 KB |
Output is correct |
7 |
Correct |
41 ms |
296276 KB |
Output is correct |
8 |
Correct |
40 ms |
296172 KB |
Output is correct |
9 |
Correct |
40 ms |
296272 KB |
Output is correct |
10 |
Correct |
40 ms |
296284 KB |
Output is correct |
11 |
Correct |
39 ms |
296272 KB |
Output is correct |
12 |
Correct |
40 ms |
296276 KB |
Output is correct |
13 |
Correct |
42 ms |
296280 KB |
Output is correct |
14 |
Correct |
40 ms |
296280 KB |
Output is correct |
15 |
Correct |
40 ms |
296308 KB |
Output is correct |
16 |
Correct |
39 ms |
296276 KB |
Output is correct |
17 |
Correct |
42 ms |
296784 KB |
Output is correct |
18 |
Correct |
42 ms |
296784 KB |
Output is correct |
19 |
Correct |
42 ms |
296732 KB |
Output is correct |
20 |
Correct |
42 ms |
296744 KB |
Output is correct |
21 |
Correct |
42 ms |
296788 KB |
Output is correct |
22 |
Correct |
42 ms |
296820 KB |
Output is correct |
23 |
Correct |
42 ms |
296748 KB |
Output is correct |
24 |
Correct |
40 ms |
296408 KB |
Output is correct |
25 |
Correct |
40 ms |
296276 KB |
Output is correct |
26 |
Correct |
41 ms |
296272 KB |
Output is correct |
27 |
Correct |
40 ms |
296272 KB |
Output is correct |
28 |
Correct |
44 ms |
296532 KB |
Output is correct |
29 |
Correct |
43 ms |
296236 KB |
Output is correct |
30 |
Correct |
48 ms |
299932 KB |
Output is correct |
31 |
Correct |
47 ms |
300124 KB |
Output is correct |
32 |
Correct |
47 ms |
299996 KB |
Output is correct |
33 |
Correct |
47 ms |
299088 KB |
Output is correct |
34 |
Correct |
51 ms |
299600 KB |
Output is correct |
35 |
Correct |
51 ms |
299860 KB |
Output is correct |
36 |
Correct |
51 ms |
299600 KB |
Output is correct |
37 |
Correct |
50 ms |
299604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
42 ms |
296272 KB |
Output is correct |
2 |
Correct |
41 ms |
296308 KB |
Output is correct |
3 |
Correct |
44 ms |
296272 KB |
Output is correct |
4 |
Correct |
45 ms |
296288 KB |
Output is correct |
5 |
Correct |
44 ms |
296276 KB |
Output is correct |
6 |
Correct |
44 ms |
296272 KB |
Output is correct |
7 |
Correct |
41 ms |
296276 KB |
Output is correct |
8 |
Correct |
40 ms |
296172 KB |
Output is correct |
9 |
Correct |
40 ms |
296272 KB |
Output is correct |
10 |
Correct |
40 ms |
296284 KB |
Output is correct |
11 |
Correct |
39 ms |
296272 KB |
Output is correct |
12 |
Correct |
40 ms |
296276 KB |
Output is correct |
13 |
Correct |
42 ms |
296280 KB |
Output is correct |
14 |
Correct |
40 ms |
296280 KB |
Output is correct |
15 |
Correct |
40 ms |
296308 KB |
Output is correct |
16 |
Correct |
39 ms |
296276 KB |
Output is correct |
17 |
Correct |
42 ms |
296784 KB |
Output is correct |
18 |
Correct |
42 ms |
296784 KB |
Output is correct |
19 |
Correct |
42 ms |
296732 KB |
Output is correct |
20 |
Correct |
42 ms |
296744 KB |
Output is correct |
21 |
Correct |
42 ms |
296788 KB |
Output is correct |
22 |
Correct |
42 ms |
296820 KB |
Output is correct |
23 |
Correct |
42 ms |
296748 KB |
Output is correct |
24 |
Correct |
40 ms |
296408 KB |
Output is correct |
25 |
Correct |
48 ms |
299932 KB |
Output is correct |
26 |
Correct |
47 ms |
300124 KB |
Output is correct |
27 |
Correct |
47 ms |
299996 KB |
Output is correct |
28 |
Correct |
47 ms |
299088 KB |
Output is correct |
29 |
Correct |
51 ms |
299600 KB |
Output is correct |
30 |
Correct |
51 ms |
299860 KB |
Output is correct |
31 |
Correct |
51 ms |
299600 KB |
Output is correct |
32 |
Correct |
50 ms |
299604 KB |
Output is correct |
33 |
Correct |
40 ms |
296276 KB |
Output is correct |
34 |
Correct |
41 ms |
296272 KB |
Output is correct |
35 |
Correct |
40 ms |
296272 KB |
Output is correct |
36 |
Correct |
44 ms |
296532 KB |
Output is correct |
37 |
Correct |
43 ms |
296236 KB |
Output is correct |
38 |
Correct |
209 ms |
338568 KB |
Output is correct |
39 |
Correct |
117 ms |
335696 KB |
Output is correct |
40 |
Correct |
115 ms |
335620 KB |
Output is correct |
41 |
Correct |
115 ms |
332884 KB |
Output is correct |
42 |
Correct |
132 ms |
343892 KB |
Output is correct |
43 |
Correct |
135 ms |
344008 KB |
Output is correct |
44 |
Correct |
141 ms |
344200 KB |
Output is correct |
45 |
Correct |
143 ms |
341680 KB |
Output is correct |
46 |
Correct |
121 ms |
331488 KB |
Output is correct |
47 |
Correct |
142 ms |
332400 KB |
Output is correct |
48 |
Correct |
209 ms |
337772 KB |
Output is correct |
49 |
Correct |
201 ms |
338968 KB |
Output is correct |
50 |
Correct |
127 ms |
317656 KB |
Output is correct |
51 |
Correct |
138 ms |
317720 KB |
Output is correct |
52 |
Correct |
195 ms |
337876 KB |
Output is correct |
53 |
Correct |
195 ms |
338384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
52 ms |
296688 KB |
Output is correct |
2 |
Correct |
53 ms |
296576 KB |
Output is correct |
3 |
Correct |
41 ms |
296788 KB |
Output is correct |
4 |
Correct |
41 ms |
296280 KB |
Output is correct |
5 |
Correct |
44 ms |
296784 KB |
Output is correct |
6 |
Correct |
45 ms |
296788 KB |
Output is correct |
7 |
Correct |
42 ms |
296880 KB |
Output is correct |
8 |
Correct |
42 ms |
296760 KB |
Output is correct |
9 |
Correct |
43 ms |
296804 KB |
Output is correct |
10 |
Correct |
43 ms |
296408 KB |
Output is correct |
11 |
Correct |
40 ms |
296620 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
40 ms |
296276 KB |
Output is correct |
2 |
Correct |
41 ms |
296272 KB |
Output is correct |
3 |
Correct |
40 ms |
296272 KB |
Output is correct |
4 |
Correct |
44 ms |
296532 KB |
Output is correct |
5 |
Correct |
43 ms |
296236 KB |
Output is correct |
6 |
Correct |
45 ms |
296304 KB |
Output is correct |
7 |
Correct |
632 ms |
501400 KB |
Output is correct |
8 |
Correct |
1287 ms |
739452 KB |
Output is correct |
9 |
Correct |
1344 ms |
739612 KB |
Output is correct |
10 |
Correct |
1309 ms |
738648 KB |
Output is correct |
11 |
Correct |
409 ms |
514660 KB |
Output is correct |
12 |
Correct |
675 ms |
711044 KB |
Output is correct |
13 |
Correct |
682 ms |
738384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
42 ms |
296272 KB |
Output is correct |
2 |
Correct |
41 ms |
296308 KB |
Output is correct |
3 |
Correct |
44 ms |
296272 KB |
Output is correct |
4 |
Correct |
45 ms |
296288 KB |
Output is correct |
5 |
Correct |
44 ms |
296276 KB |
Output is correct |
6 |
Correct |
44 ms |
296272 KB |
Output is correct |
7 |
Correct |
41 ms |
296276 KB |
Output is correct |
8 |
Correct |
40 ms |
296172 KB |
Output is correct |
9 |
Correct |
40 ms |
296272 KB |
Output is correct |
10 |
Correct |
40 ms |
296284 KB |
Output is correct |
11 |
Correct |
39 ms |
296272 KB |
Output is correct |
12 |
Correct |
40 ms |
296276 KB |
Output is correct |
13 |
Correct |
42 ms |
296280 KB |
Output is correct |
14 |
Correct |
40 ms |
296280 KB |
Output is correct |
15 |
Correct |
40 ms |
296308 KB |
Output is correct |
16 |
Correct |
39 ms |
296276 KB |
Output is correct |
17 |
Correct |
42 ms |
296784 KB |
Output is correct |
18 |
Correct |
42 ms |
296784 KB |
Output is correct |
19 |
Correct |
42 ms |
296732 KB |
Output is correct |
20 |
Correct |
42 ms |
296744 KB |
Output is correct |
21 |
Correct |
42 ms |
296788 KB |
Output is correct |
22 |
Correct |
42 ms |
296820 KB |
Output is correct |
23 |
Correct |
42 ms |
296748 KB |
Output is correct |
24 |
Correct |
40 ms |
296408 KB |
Output is correct |
25 |
Correct |
48 ms |
299932 KB |
Output is correct |
26 |
Correct |
47 ms |
300124 KB |
Output is correct |
27 |
Correct |
47 ms |
299996 KB |
Output is correct |
28 |
Correct |
47 ms |
299088 KB |
Output is correct |
29 |
Correct |
51 ms |
299600 KB |
Output is correct |
30 |
Correct |
51 ms |
299860 KB |
Output is correct |
31 |
Correct |
51 ms |
299600 KB |
Output is correct |
32 |
Correct |
50 ms |
299604 KB |
Output is correct |
33 |
Correct |
209 ms |
338568 KB |
Output is correct |
34 |
Correct |
117 ms |
335696 KB |
Output is correct |
35 |
Correct |
115 ms |
335620 KB |
Output is correct |
36 |
Correct |
115 ms |
332884 KB |
Output is correct |
37 |
Correct |
132 ms |
343892 KB |
Output is correct |
38 |
Correct |
135 ms |
344008 KB |
Output is correct |
39 |
Correct |
141 ms |
344200 KB |
Output is correct |
40 |
Correct |
143 ms |
341680 KB |
Output is correct |
41 |
Correct |
121 ms |
331488 KB |
Output is correct |
42 |
Correct |
142 ms |
332400 KB |
Output is correct |
43 |
Correct |
209 ms |
337772 KB |
Output is correct |
44 |
Correct |
201 ms |
338968 KB |
Output is correct |
45 |
Correct |
127 ms |
317656 KB |
Output is correct |
46 |
Correct |
138 ms |
317720 KB |
Output is correct |
47 |
Correct |
195 ms |
337876 KB |
Output is correct |
48 |
Correct |
195 ms |
338384 KB |
Output is correct |
49 |
Correct |
52 ms |
296688 KB |
Output is correct |
50 |
Correct |
53 ms |
296576 KB |
Output is correct |
51 |
Correct |
41 ms |
296788 KB |
Output is correct |
52 |
Correct |
41 ms |
296280 KB |
Output is correct |
53 |
Correct |
44 ms |
296784 KB |
Output is correct |
54 |
Correct |
45 ms |
296788 KB |
Output is correct |
55 |
Correct |
42 ms |
296880 KB |
Output is correct |
56 |
Correct |
42 ms |
296760 KB |
Output is correct |
57 |
Correct |
43 ms |
296804 KB |
Output is correct |
58 |
Correct |
43 ms |
296408 KB |
Output is correct |
59 |
Correct |
40 ms |
296620 KB |
Output is correct |
60 |
Correct |
45 ms |
296304 KB |
Output is correct |
61 |
Correct |
632 ms |
501400 KB |
Output is correct |
62 |
Correct |
1287 ms |
739452 KB |
Output is correct |
63 |
Correct |
1344 ms |
739612 KB |
Output is correct |
64 |
Correct |
1309 ms |
738648 KB |
Output is correct |
65 |
Correct |
409 ms |
514660 KB |
Output is correct |
66 |
Correct |
675 ms |
711044 KB |
Output is correct |
67 |
Correct |
682 ms |
738384 KB |
Output is correct |
68 |
Correct |
40 ms |
296276 KB |
Output is correct |
69 |
Correct |
41 ms |
296272 KB |
Output is correct |
70 |
Correct |
40 ms |
296272 KB |
Output is correct |
71 |
Correct |
44 ms |
296532 KB |
Output is correct |
72 |
Correct |
43 ms |
296236 KB |
Output is correct |
73 |
Execution timed out |
5058 ms |
809636 KB |
Time limit exceeded |
74 |
Halted |
0 ms |
0 KB |
- |