# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1047693 |
2024-08-07T15:07:21 Z |
vjudge1 |
Rectangles (IOI19_rect) |
C++17 |
|
2733 ms |
902288 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) {
vector<pair<int,int>> A;
vector<pair<int,int>> B;
for(auto k:gdr[i-1][j]) {
if(k[0]+1==j)continue;
A.push_back(pair<int,int>(k[0], max(0, i-k[1]-1)));
}
for(auto k:gdc[i][j-1]) {
if(k[0]+1 == i)continue;
B.push_back(pair<int,int>(max(0, j-k[1]-1), k[0]));
}
sort(A.begin(),A.end());
sort(B.begin(),B.end());
// A[0] >= B[0]
//
// B[1] >= A[1]
int p1 = 0;
for(auto k:A) {
while(p1 < (int)B.size() and B[p1].first <= k.first) {
upd(B[p1].second, 1);
p1++;
}
ans+=qry(k.second);
}
while(p1 < B.size()) {
upd(B[p1].second, 1);
p1++;
}
for(auto k:B)upd(k.second, -1);
}
}
}
return ans;
}
Compilation message
rect.cpp: In function 'long long int count_rectangles(std::vector<std::vector<int> >)':
rect.cpp:131:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
131 | while(p1 < B.size()) {
| ~~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
40 ms |
296284 KB |
Output is correct |
2 |
Correct |
40 ms |
296272 KB |
Output is correct |
3 |
Correct |
41 ms |
296276 KB |
Output is correct |
4 |
Correct |
40 ms |
296276 KB |
Output is correct |
5 |
Correct |
42 ms |
296272 KB |
Output is correct |
6 |
Correct |
41 ms |
296276 KB |
Output is correct |
7 |
Correct |
45 ms |
296284 KB |
Output is correct |
8 |
Correct |
41 ms |
296276 KB |
Output is correct |
9 |
Correct |
40 ms |
296284 KB |
Output is correct |
10 |
Correct |
41 ms |
296276 KB |
Output is correct |
11 |
Correct |
42 ms |
296148 KB |
Output is correct |
12 |
Correct |
42 ms |
296272 KB |
Output is correct |
13 |
Correct |
40 ms |
296276 KB |
Output is correct |
14 |
Correct |
42 ms |
296276 KB |
Output is correct |
15 |
Correct |
40 ms |
296332 KB |
Output is correct |
16 |
Correct |
41 ms |
296280 KB |
Output is correct |
17 |
Correct |
40 ms |
296272 KB |
Output is correct |
18 |
Correct |
42 ms |
296284 KB |
Output is correct |
19 |
Correct |
43 ms |
296280 KB |
Output is correct |
20 |
Correct |
41 ms |
296148 KB |
Output is correct |
21 |
Correct |
41 ms |
296148 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
40 ms |
296284 KB |
Output is correct |
2 |
Correct |
40 ms |
296272 KB |
Output is correct |
3 |
Correct |
41 ms |
296276 KB |
Output is correct |
4 |
Correct |
40 ms |
296276 KB |
Output is correct |
5 |
Correct |
42 ms |
296272 KB |
Output is correct |
6 |
Correct |
41 ms |
296276 KB |
Output is correct |
7 |
Correct |
45 ms |
296284 KB |
Output is correct |
8 |
Correct |
41 ms |
296276 KB |
Output is correct |
9 |
Correct |
40 ms |
296284 KB |
Output is correct |
10 |
Correct |
41 ms |
296276 KB |
Output is correct |
11 |
Correct |
42 ms |
296148 KB |
Output is correct |
12 |
Correct |
42 ms |
296272 KB |
Output is correct |
13 |
Correct |
40 ms |
296276 KB |
Output is correct |
14 |
Correct |
42 ms |
296276 KB |
Output is correct |
15 |
Correct |
40 ms |
296332 KB |
Output is correct |
16 |
Correct |
41 ms |
296280 KB |
Output is correct |
17 |
Correct |
40 ms |
296272 KB |
Output is correct |
18 |
Correct |
42 ms |
296284 KB |
Output is correct |
19 |
Correct |
43 ms |
296280 KB |
Output is correct |
20 |
Correct |
41 ms |
296148 KB |
Output is correct |
21 |
Correct |
41 ms |
296148 KB |
Output is correct |
22 |
Correct |
42 ms |
296796 KB |
Output is correct |
23 |
Correct |
41 ms |
296784 KB |
Output is correct |
24 |
Correct |
42 ms |
296836 KB |
Output is correct |
25 |
Correct |
45 ms |
296788 KB |
Output is correct |
26 |
Correct |
44 ms |
296784 KB |
Output is correct |
27 |
Correct |
43 ms |
296788 KB |
Output is correct |
28 |
Correct |
42 ms |
296784 KB |
Output is correct |
29 |
Correct |
42 ms |
296580 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
40 ms |
296284 KB |
Output is correct |
2 |
Correct |
40 ms |
296272 KB |
Output is correct |
3 |
Correct |
41 ms |
296276 KB |
Output is correct |
4 |
Correct |
40 ms |
296276 KB |
Output is correct |
5 |
Correct |
42 ms |
296272 KB |
Output is correct |
6 |
Correct |
41 ms |
296276 KB |
Output is correct |
7 |
Correct |
45 ms |
296284 KB |
Output is correct |
8 |
Correct |
41 ms |
296276 KB |
Output is correct |
9 |
Correct |
40 ms |
296284 KB |
Output is correct |
10 |
Correct |
41 ms |
296276 KB |
Output is correct |
11 |
Correct |
42 ms |
296148 KB |
Output is correct |
12 |
Correct |
42 ms |
296272 KB |
Output is correct |
13 |
Correct |
40 ms |
296276 KB |
Output is correct |
14 |
Correct |
42 ms |
296276 KB |
Output is correct |
15 |
Correct |
40 ms |
296332 KB |
Output is correct |
16 |
Correct |
41 ms |
296280 KB |
Output is correct |
17 |
Correct |
42 ms |
296796 KB |
Output is correct |
18 |
Correct |
41 ms |
296784 KB |
Output is correct |
19 |
Correct |
42 ms |
296836 KB |
Output is correct |
20 |
Correct |
45 ms |
296788 KB |
Output is correct |
21 |
Correct |
44 ms |
296784 KB |
Output is correct |
22 |
Correct |
43 ms |
296788 KB |
Output is correct |
23 |
Correct |
42 ms |
296784 KB |
Output is correct |
24 |
Correct |
42 ms |
296580 KB |
Output is correct |
25 |
Correct |
40 ms |
296272 KB |
Output is correct |
26 |
Correct |
42 ms |
296284 KB |
Output is correct |
27 |
Correct |
43 ms |
296280 KB |
Output is correct |
28 |
Correct |
41 ms |
296148 KB |
Output is correct |
29 |
Correct |
41 ms |
296148 KB |
Output is correct |
30 |
Correct |
51 ms |
300120 KB |
Output is correct |
31 |
Correct |
49 ms |
300036 KB |
Output is correct |
32 |
Correct |
50 ms |
300112 KB |
Output is correct |
33 |
Correct |
50 ms |
299088 KB |
Output is correct |
34 |
Correct |
53 ms |
299604 KB |
Output is correct |
35 |
Correct |
54 ms |
299868 KB |
Output is correct |
36 |
Correct |
55 ms |
299704 KB |
Output is correct |
37 |
Correct |
53 ms |
299612 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
40 ms |
296284 KB |
Output is correct |
2 |
Correct |
40 ms |
296272 KB |
Output is correct |
3 |
Correct |
41 ms |
296276 KB |
Output is correct |
4 |
Correct |
40 ms |
296276 KB |
Output is correct |
5 |
Correct |
42 ms |
296272 KB |
Output is correct |
6 |
Correct |
41 ms |
296276 KB |
Output is correct |
7 |
Correct |
45 ms |
296284 KB |
Output is correct |
8 |
Correct |
41 ms |
296276 KB |
Output is correct |
9 |
Correct |
40 ms |
296284 KB |
Output is correct |
10 |
Correct |
41 ms |
296276 KB |
Output is correct |
11 |
Correct |
42 ms |
296148 KB |
Output is correct |
12 |
Correct |
42 ms |
296272 KB |
Output is correct |
13 |
Correct |
40 ms |
296276 KB |
Output is correct |
14 |
Correct |
42 ms |
296276 KB |
Output is correct |
15 |
Correct |
40 ms |
296332 KB |
Output is correct |
16 |
Correct |
41 ms |
296280 KB |
Output is correct |
17 |
Correct |
42 ms |
296796 KB |
Output is correct |
18 |
Correct |
41 ms |
296784 KB |
Output is correct |
19 |
Correct |
42 ms |
296836 KB |
Output is correct |
20 |
Correct |
45 ms |
296788 KB |
Output is correct |
21 |
Correct |
44 ms |
296784 KB |
Output is correct |
22 |
Correct |
43 ms |
296788 KB |
Output is correct |
23 |
Correct |
42 ms |
296784 KB |
Output is correct |
24 |
Correct |
42 ms |
296580 KB |
Output is correct |
25 |
Correct |
51 ms |
300120 KB |
Output is correct |
26 |
Correct |
49 ms |
300036 KB |
Output is correct |
27 |
Correct |
50 ms |
300112 KB |
Output is correct |
28 |
Correct |
50 ms |
299088 KB |
Output is correct |
29 |
Correct |
53 ms |
299604 KB |
Output is correct |
30 |
Correct |
54 ms |
299868 KB |
Output is correct |
31 |
Correct |
55 ms |
299704 KB |
Output is correct |
32 |
Correct |
53 ms |
299612 KB |
Output is correct |
33 |
Correct |
40 ms |
296272 KB |
Output is correct |
34 |
Correct |
42 ms |
296284 KB |
Output is correct |
35 |
Correct |
43 ms |
296280 KB |
Output is correct |
36 |
Correct |
41 ms |
296148 KB |
Output is correct |
37 |
Correct |
41 ms |
296148 KB |
Output is correct |
38 |
Correct |
122 ms |
337772 KB |
Output is correct |
39 |
Correct |
134 ms |
335208 KB |
Output is correct |
40 |
Correct |
125 ms |
334848 KB |
Output is correct |
41 |
Correct |
123 ms |
332112 KB |
Output is correct |
42 |
Correct |
152 ms |
343120 KB |
Output is correct |
43 |
Correct |
159 ms |
343120 KB |
Output is correct |
44 |
Correct |
152 ms |
343120 KB |
Output is correct |
45 |
Correct |
148 ms |
340560 KB |
Output is correct |
46 |
Correct |
133 ms |
331484 KB |
Output is correct |
47 |
Correct |
149 ms |
332136 KB |
Output is correct |
48 |
Correct |
216 ms |
337232 KB |
Output is correct |
49 |
Correct |
227 ms |
338076 KB |
Output is correct |
50 |
Correct |
123 ms |
317068 KB |
Output is correct |
51 |
Correct |
129 ms |
317012 KB |
Output is correct |
52 |
Correct |
222 ms |
337256 KB |
Output is correct |
53 |
Correct |
221 ms |
337356 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
46 ms |
296784 KB |
Output is correct |
2 |
Correct |
42 ms |
296660 KB |
Output is correct |
3 |
Correct |
42 ms |
296788 KB |
Output is correct |
4 |
Correct |
40 ms |
296284 KB |
Output is correct |
5 |
Correct |
43 ms |
296788 KB |
Output is correct |
6 |
Correct |
44 ms |
296788 KB |
Output is correct |
7 |
Correct |
43 ms |
296788 KB |
Output is correct |
8 |
Correct |
43 ms |
296740 KB |
Output is correct |
9 |
Correct |
44 ms |
296784 KB |
Output is correct |
10 |
Correct |
41 ms |
296272 KB |
Output is correct |
11 |
Correct |
42 ms |
296404 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
40 ms |
296272 KB |
Output is correct |
2 |
Correct |
42 ms |
296284 KB |
Output is correct |
3 |
Correct |
43 ms |
296280 KB |
Output is correct |
4 |
Correct |
41 ms |
296148 KB |
Output is correct |
5 |
Correct |
41 ms |
296148 KB |
Output is correct |
6 |
Correct |
43 ms |
296276 KB |
Output is correct |
7 |
Correct |
678 ms |
499864 KB |
Output is correct |
8 |
Correct |
1457 ms |
738672 KB |
Output is correct |
9 |
Correct |
1502 ms |
741716 KB |
Output is correct |
10 |
Correct |
1447 ms |
739012 KB |
Output is correct |
11 |
Correct |
389 ms |
515156 KB |
Output is correct |
12 |
Correct |
718 ms |
711704 KB |
Output is correct |
13 |
Correct |
740 ms |
739200 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
40 ms |
296284 KB |
Output is correct |
2 |
Correct |
40 ms |
296272 KB |
Output is correct |
3 |
Correct |
41 ms |
296276 KB |
Output is correct |
4 |
Correct |
40 ms |
296276 KB |
Output is correct |
5 |
Correct |
42 ms |
296272 KB |
Output is correct |
6 |
Correct |
41 ms |
296276 KB |
Output is correct |
7 |
Correct |
45 ms |
296284 KB |
Output is correct |
8 |
Correct |
41 ms |
296276 KB |
Output is correct |
9 |
Correct |
40 ms |
296284 KB |
Output is correct |
10 |
Correct |
41 ms |
296276 KB |
Output is correct |
11 |
Correct |
42 ms |
296148 KB |
Output is correct |
12 |
Correct |
42 ms |
296272 KB |
Output is correct |
13 |
Correct |
40 ms |
296276 KB |
Output is correct |
14 |
Correct |
42 ms |
296276 KB |
Output is correct |
15 |
Correct |
40 ms |
296332 KB |
Output is correct |
16 |
Correct |
41 ms |
296280 KB |
Output is correct |
17 |
Correct |
42 ms |
296796 KB |
Output is correct |
18 |
Correct |
41 ms |
296784 KB |
Output is correct |
19 |
Correct |
42 ms |
296836 KB |
Output is correct |
20 |
Correct |
45 ms |
296788 KB |
Output is correct |
21 |
Correct |
44 ms |
296784 KB |
Output is correct |
22 |
Correct |
43 ms |
296788 KB |
Output is correct |
23 |
Correct |
42 ms |
296784 KB |
Output is correct |
24 |
Correct |
42 ms |
296580 KB |
Output is correct |
25 |
Correct |
51 ms |
300120 KB |
Output is correct |
26 |
Correct |
49 ms |
300036 KB |
Output is correct |
27 |
Correct |
50 ms |
300112 KB |
Output is correct |
28 |
Correct |
50 ms |
299088 KB |
Output is correct |
29 |
Correct |
53 ms |
299604 KB |
Output is correct |
30 |
Correct |
54 ms |
299868 KB |
Output is correct |
31 |
Correct |
55 ms |
299704 KB |
Output is correct |
32 |
Correct |
53 ms |
299612 KB |
Output is correct |
33 |
Correct |
122 ms |
337772 KB |
Output is correct |
34 |
Correct |
134 ms |
335208 KB |
Output is correct |
35 |
Correct |
125 ms |
334848 KB |
Output is correct |
36 |
Correct |
123 ms |
332112 KB |
Output is correct |
37 |
Correct |
152 ms |
343120 KB |
Output is correct |
38 |
Correct |
159 ms |
343120 KB |
Output is correct |
39 |
Correct |
152 ms |
343120 KB |
Output is correct |
40 |
Correct |
148 ms |
340560 KB |
Output is correct |
41 |
Correct |
133 ms |
331484 KB |
Output is correct |
42 |
Correct |
149 ms |
332136 KB |
Output is correct |
43 |
Correct |
216 ms |
337232 KB |
Output is correct |
44 |
Correct |
227 ms |
338076 KB |
Output is correct |
45 |
Correct |
123 ms |
317068 KB |
Output is correct |
46 |
Correct |
129 ms |
317012 KB |
Output is correct |
47 |
Correct |
222 ms |
337256 KB |
Output is correct |
48 |
Correct |
221 ms |
337356 KB |
Output is correct |
49 |
Correct |
46 ms |
296784 KB |
Output is correct |
50 |
Correct |
42 ms |
296660 KB |
Output is correct |
51 |
Correct |
42 ms |
296788 KB |
Output is correct |
52 |
Correct |
40 ms |
296284 KB |
Output is correct |
53 |
Correct |
43 ms |
296788 KB |
Output is correct |
54 |
Correct |
44 ms |
296788 KB |
Output is correct |
55 |
Correct |
43 ms |
296788 KB |
Output is correct |
56 |
Correct |
43 ms |
296740 KB |
Output is correct |
57 |
Correct |
44 ms |
296784 KB |
Output is correct |
58 |
Correct |
41 ms |
296272 KB |
Output is correct |
59 |
Correct |
42 ms |
296404 KB |
Output is correct |
60 |
Correct |
43 ms |
296276 KB |
Output is correct |
61 |
Correct |
678 ms |
499864 KB |
Output is correct |
62 |
Correct |
1457 ms |
738672 KB |
Output is correct |
63 |
Correct |
1502 ms |
741716 KB |
Output is correct |
64 |
Correct |
1447 ms |
739012 KB |
Output is correct |
65 |
Correct |
389 ms |
515156 KB |
Output is correct |
66 |
Correct |
718 ms |
711704 KB |
Output is correct |
67 |
Correct |
740 ms |
739200 KB |
Output is correct |
68 |
Correct |
40 ms |
296272 KB |
Output is correct |
69 |
Correct |
42 ms |
296284 KB |
Output is correct |
70 |
Correct |
43 ms |
296280 KB |
Output is correct |
71 |
Correct |
41 ms |
296148 KB |
Output is correct |
72 |
Correct |
41 ms |
296148 KB |
Output is correct |
73 |
Correct |
1118 ms |
810132 KB |
Output is correct |
74 |
Correct |
1160 ms |
767600 KB |
Output is correct |
75 |
Correct |
1141 ms |
767568 KB |
Output is correct |
76 |
Correct |
1151 ms |
736444 KB |
Output is correct |
77 |
Correct |
1829 ms |
854356 KB |
Output is correct |
78 |
Correct |
1497 ms |
604780 KB |
Output is correct |
79 |
Correct |
1643 ms |
622124 KB |
Output is correct |
80 |
Correct |
2733 ms |
822260 KB |
Output is correct |
81 |
Correct |
1715 ms |
634624 KB |
Output is correct |
82 |
Correct |
2185 ms |
747652 KB |
Output is correct |
83 |
Correct |
2714 ms |
860508 KB |
Output is correct |
84 |
Correct |
1516 ms |
624048 KB |
Output is correct |
85 |
Correct |
2593 ms |
855132 KB |
Output is correct |
86 |
Correct |
2449 ms |
839660 KB |
Output is correct |
87 |
Correct |
1033 ms |
664024 KB |
Output is correct |
88 |
Correct |
1887 ms |
901476 KB |
Output is correct |
89 |
Correct |
1851 ms |
902288 KB |
Output is correct |
90 |
Correct |
1883 ms |
902144 KB |
Output is correct |