# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
928816 |
2024-02-17T06:11:06 Z |
knon0501 |
Rectangles (IOI19_rect) |
C++17 |
|
1403 ms |
1048576 KB |
#include "rect.h"
#include <bits/stdc++.h>
using namespace std;
vector<int> b[2505][2505];
vector<int> c[2505][2505];
vector<pair<int,int>> d[2505][2505];
vector<pair<int,int>> e[2505][2505];
int lef[2505][2505];
int rig[2505][2505];
int up[2505][2505];
int down[2505][2505];
vector<vector<int>> v;
long long count_rectangles(std::vector<std::vector<int> > a) {
int n = a.size();
int m = a[0].size();
for(int i=1 ; i<n-1 ; i++){
stack<int> S;
for(int j=0 ; j<m ; j++){
bool flag = true;
while(!S.empty() && a[i][S.top()] <= a[i][j]){
int x = S.top();
if(x +1 <j && flag)
b[x+1][j-1].push_back(i);
if(a[i][S.top()]==a[i][j])flag=false;
S.pop();
}
if(!S.empty() ){
int x = S.top();
lef[i][j] = x;
if(x+1<j && flag)
b[x+1][j-1].push_back(i);
}
else{
lef[i][j]=-1;
}
S.push(j);
}
while(!S.empty())S.pop();
for(int j=m-1; j>=0 ; j--){
while(!S.empty() && a[i][S.top()] <= a[i][j]){
S.pop();
}
if(!S.empty() ){
int x = S.top();
rig[i][j] = x;
}
else{
rig[i][j]=-1;
}
S.push(j);
}
}
for(int i=1 ; i<m-1 ; i++){
stack<int> S;
for(int j=0 ; j<n ; j++){
bool flag = true;
while(!S.empty() && a[S.top()][i] <= a[j][i]){
int x = S.top();
if(x +1 <j && flag)
c[x+1][j-1].push_back(i);
if(a[S.top()][i]==a[j][i])flag=false;
S.pop();
}
if(!S.empty() ){
int x = S.top();
up[j][i]=x;
if(x+1<j && flag)
c[x+1][j-1].push_back(i);
}
else{
up[j][i]=-1;
}
S.push(j);
}
while(!S.empty())S.pop();
for(int j=n-1 ; j>=0 ; j--){
while(!S.empty() && a[S.top()][i] <= a[j][i]){
S.pop();
}
if(!S.empty() ){
int x = S.top();
down[j][i]=x;
}
else{
down[j][i]=-1;
}
S.push(j);
}
}
std::vector<vector<int>>().swap(a);
long long ans = 0;
for(int i=1 ; i<m ; i++){
for(int j=i ; j<m ; j++){
reverse(b[i][j].begin(),b[i][j].end());
int prv = -1;
int y;
for(auto x: b[i][j]){
if(x != prv-1){
if(prv>=0)
d[i][j].push_back({prv,y});
y=x;
}
prv=x;
}
if(prv>=0){
d[i][j].push_back({prv,y});
}
sort(d[i][j].begin(),d[i][j].end());
std::vector<int>().swap(b[i][j]);
}
}
for(int i=1 ; i<n ; i++){
for(int j=i ; j<n ; j++){
reverse(c[i][j].begin(),c[i][j].end());
int prv = -1;
int y;
for(auto x: c[i][j]){
if(x != prv-1){
if(prv>=0)
e[i][j].push_back({prv,y});
y=x;
}
prv=x;
}
if(prv>=0){
e[i][j].push_back({prv,y});
}
sort(e[i][j].begin(),e[i][j].end());
std::vector<int>().swap(c[i][j]);
}
}
for(int i = 1 ; i<n-1 ; i++){
for(int j=1 ; j<m-1 ; j++){
int x = lef[i][j];
int y = rig[i][j];
int z = up[i][j];
int w = down[i][j];
v.push_back({x,y,z,w});
}
}
sort(v.begin(),v.end());
v.erase(unique(v.begin(),v.end()),v.end());
for(auto vv: v){
int x=vv[0];
int y = vv[1];
int z =vv[2];
int w = vv[3];
if(x==-1 ||y==-1 || z==-1 || w==-1)continue;
auto k = upper_bound(d[x+1][y-1].begin(),d[x+1][y-1].end(),make_pair(z+1,10000000));
if(k== d[x+1][y-1].begin())continue;
if((--k)->second <w-1)continue;
//cout<<z+1<<" "<<w-1<<" "<<e[z+1][w-1].size()<<" "<<c[z+1][w-1].size()<<endl;
auto t = upper_bound(e[z+1][w-1].begin(),e[z+1][w-1].end(),make_pair(x+1,10000000));
if(t== e[z+1][w-1].begin())continue;
if((--t)->second <y-1)continue;
ans++;
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
130 ms |
597488 KB |
Output is correct |
2 |
Correct |
133 ms |
601800 KB |
Output is correct |
3 |
Correct |
139 ms |
601852 KB |
Output is correct |
4 |
Correct |
130 ms |
601680 KB |
Output is correct |
5 |
Correct |
136 ms |
601684 KB |
Output is correct |
6 |
Correct |
129 ms |
601872 KB |
Output is correct |
7 |
Correct |
134 ms |
601684 KB |
Output is correct |
8 |
Correct |
134 ms |
597528 KB |
Output is correct |
9 |
Correct |
130 ms |
601740 KB |
Output is correct |
10 |
Correct |
139 ms |
601640 KB |
Output is correct |
11 |
Correct |
141 ms |
601640 KB |
Output is correct |
12 |
Correct |
135 ms |
601828 KB |
Output is correct |
13 |
Correct |
130 ms |
591292 KB |
Output is correct |
14 |
Correct |
129 ms |
595540 KB |
Output is correct |
15 |
Correct |
130 ms |
597584 KB |
Output is correct |
16 |
Correct |
142 ms |
597524 KB |
Output is correct |
17 |
Correct |
135 ms |
591440 KB |
Output is correct |
18 |
Correct |
135 ms |
593528 KB |
Output is correct |
19 |
Correct |
134 ms |
601828 KB |
Output is correct |
20 |
Correct |
131 ms |
601680 KB |
Output is correct |
21 |
Correct |
132 ms |
595412 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
130 ms |
597488 KB |
Output is correct |
2 |
Correct |
133 ms |
601800 KB |
Output is correct |
3 |
Correct |
139 ms |
601852 KB |
Output is correct |
4 |
Correct |
130 ms |
601680 KB |
Output is correct |
5 |
Correct |
136 ms |
601684 KB |
Output is correct |
6 |
Correct |
129 ms |
601872 KB |
Output is correct |
7 |
Correct |
134 ms |
601684 KB |
Output is correct |
8 |
Correct |
134 ms |
597528 KB |
Output is correct |
9 |
Correct |
130 ms |
601740 KB |
Output is correct |
10 |
Correct |
139 ms |
601640 KB |
Output is correct |
11 |
Correct |
141 ms |
601640 KB |
Output is correct |
12 |
Correct |
135 ms |
601828 KB |
Output is correct |
13 |
Correct |
130 ms |
591292 KB |
Output is correct |
14 |
Correct |
129 ms |
595540 KB |
Output is correct |
15 |
Correct |
130 ms |
597584 KB |
Output is correct |
16 |
Correct |
142 ms |
597524 KB |
Output is correct |
17 |
Correct |
135 ms |
591440 KB |
Output is correct |
18 |
Correct |
135 ms |
593528 KB |
Output is correct |
19 |
Correct |
134 ms |
601828 KB |
Output is correct |
20 |
Correct |
131 ms |
601680 KB |
Output is correct |
21 |
Correct |
132 ms |
595412 KB |
Output is correct |
22 |
Correct |
136 ms |
606276 KB |
Output is correct |
23 |
Correct |
137 ms |
606304 KB |
Output is correct |
24 |
Correct |
137 ms |
606216 KB |
Output is correct |
25 |
Correct |
132 ms |
606308 KB |
Output is correct |
26 |
Correct |
140 ms |
606212 KB |
Output is correct |
27 |
Correct |
133 ms |
606268 KB |
Output is correct |
28 |
Correct |
131 ms |
606292 KB |
Output is correct |
29 |
Correct |
140 ms |
606140 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
130 ms |
597488 KB |
Output is correct |
2 |
Correct |
133 ms |
601800 KB |
Output is correct |
3 |
Correct |
139 ms |
601852 KB |
Output is correct |
4 |
Correct |
130 ms |
601680 KB |
Output is correct |
5 |
Correct |
136 ms |
601684 KB |
Output is correct |
6 |
Correct |
129 ms |
601872 KB |
Output is correct |
7 |
Correct |
134 ms |
601684 KB |
Output is correct |
8 |
Correct |
134 ms |
597528 KB |
Output is correct |
9 |
Correct |
130 ms |
601740 KB |
Output is correct |
10 |
Correct |
139 ms |
601640 KB |
Output is correct |
11 |
Correct |
141 ms |
601640 KB |
Output is correct |
12 |
Correct |
135 ms |
601828 KB |
Output is correct |
13 |
Correct |
130 ms |
591292 KB |
Output is correct |
14 |
Correct |
129 ms |
595540 KB |
Output is correct |
15 |
Correct |
130 ms |
597584 KB |
Output is correct |
16 |
Correct |
142 ms |
597524 KB |
Output is correct |
17 |
Correct |
136 ms |
606276 KB |
Output is correct |
18 |
Correct |
137 ms |
606304 KB |
Output is correct |
19 |
Correct |
137 ms |
606216 KB |
Output is correct |
20 |
Correct |
132 ms |
606308 KB |
Output is correct |
21 |
Correct |
140 ms |
606212 KB |
Output is correct |
22 |
Correct |
133 ms |
606268 KB |
Output is correct |
23 |
Correct |
131 ms |
606292 KB |
Output is correct |
24 |
Correct |
140 ms |
606140 KB |
Output is correct |
25 |
Correct |
135 ms |
591440 KB |
Output is correct |
26 |
Correct |
135 ms |
593528 KB |
Output is correct |
27 |
Correct |
134 ms |
601828 KB |
Output is correct |
28 |
Correct |
131 ms |
601680 KB |
Output is correct |
29 |
Correct |
132 ms |
595412 KB |
Output is correct |
30 |
Correct |
143 ms |
608468 KB |
Output is correct |
31 |
Correct |
142 ms |
608528 KB |
Output is correct |
32 |
Correct |
149 ms |
608508 KB |
Output is correct |
33 |
Correct |
148 ms |
608832 KB |
Output is correct |
34 |
Correct |
166 ms |
609292 KB |
Output is correct |
35 |
Correct |
149 ms |
609292 KB |
Output is correct |
36 |
Correct |
147 ms |
609296 KB |
Output is correct |
37 |
Correct |
165 ms |
609260 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
130 ms |
597488 KB |
Output is correct |
2 |
Correct |
133 ms |
601800 KB |
Output is correct |
3 |
Correct |
139 ms |
601852 KB |
Output is correct |
4 |
Correct |
130 ms |
601680 KB |
Output is correct |
5 |
Correct |
136 ms |
601684 KB |
Output is correct |
6 |
Correct |
129 ms |
601872 KB |
Output is correct |
7 |
Correct |
134 ms |
601684 KB |
Output is correct |
8 |
Correct |
134 ms |
597528 KB |
Output is correct |
9 |
Correct |
130 ms |
601740 KB |
Output is correct |
10 |
Correct |
139 ms |
601640 KB |
Output is correct |
11 |
Correct |
141 ms |
601640 KB |
Output is correct |
12 |
Correct |
135 ms |
601828 KB |
Output is correct |
13 |
Correct |
130 ms |
591292 KB |
Output is correct |
14 |
Correct |
129 ms |
595540 KB |
Output is correct |
15 |
Correct |
130 ms |
597584 KB |
Output is correct |
16 |
Correct |
142 ms |
597524 KB |
Output is correct |
17 |
Correct |
136 ms |
606276 KB |
Output is correct |
18 |
Correct |
137 ms |
606304 KB |
Output is correct |
19 |
Correct |
137 ms |
606216 KB |
Output is correct |
20 |
Correct |
132 ms |
606308 KB |
Output is correct |
21 |
Correct |
140 ms |
606212 KB |
Output is correct |
22 |
Correct |
133 ms |
606268 KB |
Output is correct |
23 |
Correct |
131 ms |
606292 KB |
Output is correct |
24 |
Correct |
140 ms |
606140 KB |
Output is correct |
25 |
Correct |
143 ms |
608468 KB |
Output is correct |
26 |
Correct |
142 ms |
608528 KB |
Output is correct |
27 |
Correct |
149 ms |
608508 KB |
Output is correct |
28 |
Correct |
148 ms |
608832 KB |
Output is correct |
29 |
Correct |
166 ms |
609292 KB |
Output is correct |
30 |
Correct |
149 ms |
609292 KB |
Output is correct |
31 |
Correct |
147 ms |
609296 KB |
Output is correct |
32 |
Correct |
165 ms |
609260 KB |
Output is correct |
33 |
Correct |
135 ms |
591440 KB |
Output is correct |
34 |
Correct |
135 ms |
593528 KB |
Output is correct |
35 |
Correct |
134 ms |
601828 KB |
Output is correct |
36 |
Correct |
131 ms |
601680 KB |
Output is correct |
37 |
Correct |
132 ms |
595412 KB |
Output is correct |
38 |
Correct |
296 ms |
674344 KB |
Output is correct |
39 |
Correct |
283 ms |
675140 KB |
Output is correct |
40 |
Correct |
296 ms |
674884 KB |
Output is correct |
41 |
Correct |
281 ms |
674344 KB |
Output is correct |
42 |
Correct |
287 ms |
659276 KB |
Output is correct |
43 |
Correct |
298 ms |
660084 KB |
Output is correct |
44 |
Correct |
300 ms |
659292 KB |
Output is correct |
45 |
Correct |
283 ms |
654092 KB |
Output is correct |
46 |
Correct |
301 ms |
662124 KB |
Output is correct |
47 |
Correct |
323 ms |
662720 KB |
Output is correct |
48 |
Correct |
398 ms |
669544 KB |
Output is correct |
49 |
Correct |
398 ms |
670392 KB |
Output is correct |
50 |
Correct |
258 ms |
650160 KB |
Output is correct |
51 |
Correct |
254 ms |
633760 KB |
Output is correct |
52 |
Correct |
382 ms |
666820 KB |
Output is correct |
53 |
Correct |
385 ms |
666864 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
143 ms |
597976 KB |
Output is correct |
2 |
Correct |
138 ms |
597680 KB |
Output is correct |
3 |
Correct |
139 ms |
597652 KB |
Output is correct |
4 |
Correct |
131 ms |
595472 KB |
Output is correct |
5 |
Correct |
146 ms |
597840 KB |
Output is correct |
6 |
Correct |
140 ms |
597844 KB |
Output is correct |
7 |
Correct |
141 ms |
597808 KB |
Output is correct |
8 |
Correct |
145 ms |
597840 KB |
Output is correct |
9 |
Correct |
141 ms |
597924 KB |
Output is correct |
10 |
Correct |
139 ms |
593540 KB |
Output is correct |
11 |
Correct |
140 ms |
593420 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
135 ms |
591440 KB |
Output is correct |
2 |
Correct |
135 ms |
593528 KB |
Output is correct |
3 |
Correct |
134 ms |
601828 KB |
Output is correct |
4 |
Correct |
131 ms |
601680 KB |
Output is correct |
5 |
Correct |
132 ms |
595412 KB |
Output is correct |
6 |
Correct |
134 ms |
597528 KB |
Output is correct |
7 |
Correct |
1403 ms |
840460 KB |
Output is correct |
8 |
Runtime error |
832 ms |
1048576 KB |
Execution killed with signal 9 |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
130 ms |
597488 KB |
Output is correct |
2 |
Correct |
133 ms |
601800 KB |
Output is correct |
3 |
Correct |
139 ms |
601852 KB |
Output is correct |
4 |
Correct |
130 ms |
601680 KB |
Output is correct |
5 |
Correct |
136 ms |
601684 KB |
Output is correct |
6 |
Correct |
129 ms |
601872 KB |
Output is correct |
7 |
Correct |
134 ms |
601684 KB |
Output is correct |
8 |
Correct |
134 ms |
597528 KB |
Output is correct |
9 |
Correct |
130 ms |
601740 KB |
Output is correct |
10 |
Correct |
139 ms |
601640 KB |
Output is correct |
11 |
Correct |
141 ms |
601640 KB |
Output is correct |
12 |
Correct |
135 ms |
601828 KB |
Output is correct |
13 |
Correct |
130 ms |
591292 KB |
Output is correct |
14 |
Correct |
129 ms |
595540 KB |
Output is correct |
15 |
Correct |
130 ms |
597584 KB |
Output is correct |
16 |
Correct |
142 ms |
597524 KB |
Output is correct |
17 |
Correct |
136 ms |
606276 KB |
Output is correct |
18 |
Correct |
137 ms |
606304 KB |
Output is correct |
19 |
Correct |
137 ms |
606216 KB |
Output is correct |
20 |
Correct |
132 ms |
606308 KB |
Output is correct |
21 |
Correct |
140 ms |
606212 KB |
Output is correct |
22 |
Correct |
133 ms |
606268 KB |
Output is correct |
23 |
Correct |
131 ms |
606292 KB |
Output is correct |
24 |
Correct |
140 ms |
606140 KB |
Output is correct |
25 |
Correct |
143 ms |
608468 KB |
Output is correct |
26 |
Correct |
142 ms |
608528 KB |
Output is correct |
27 |
Correct |
149 ms |
608508 KB |
Output is correct |
28 |
Correct |
148 ms |
608832 KB |
Output is correct |
29 |
Correct |
166 ms |
609292 KB |
Output is correct |
30 |
Correct |
149 ms |
609292 KB |
Output is correct |
31 |
Correct |
147 ms |
609296 KB |
Output is correct |
32 |
Correct |
165 ms |
609260 KB |
Output is correct |
33 |
Correct |
296 ms |
674344 KB |
Output is correct |
34 |
Correct |
283 ms |
675140 KB |
Output is correct |
35 |
Correct |
296 ms |
674884 KB |
Output is correct |
36 |
Correct |
281 ms |
674344 KB |
Output is correct |
37 |
Correct |
287 ms |
659276 KB |
Output is correct |
38 |
Correct |
298 ms |
660084 KB |
Output is correct |
39 |
Correct |
300 ms |
659292 KB |
Output is correct |
40 |
Correct |
283 ms |
654092 KB |
Output is correct |
41 |
Correct |
301 ms |
662124 KB |
Output is correct |
42 |
Correct |
323 ms |
662720 KB |
Output is correct |
43 |
Correct |
398 ms |
669544 KB |
Output is correct |
44 |
Correct |
398 ms |
670392 KB |
Output is correct |
45 |
Correct |
258 ms |
650160 KB |
Output is correct |
46 |
Correct |
254 ms |
633760 KB |
Output is correct |
47 |
Correct |
382 ms |
666820 KB |
Output is correct |
48 |
Correct |
385 ms |
666864 KB |
Output is correct |
49 |
Correct |
143 ms |
597976 KB |
Output is correct |
50 |
Correct |
138 ms |
597680 KB |
Output is correct |
51 |
Correct |
139 ms |
597652 KB |
Output is correct |
52 |
Correct |
131 ms |
595472 KB |
Output is correct |
53 |
Correct |
146 ms |
597840 KB |
Output is correct |
54 |
Correct |
140 ms |
597844 KB |
Output is correct |
55 |
Correct |
141 ms |
597808 KB |
Output is correct |
56 |
Correct |
145 ms |
597840 KB |
Output is correct |
57 |
Correct |
141 ms |
597924 KB |
Output is correct |
58 |
Correct |
139 ms |
593540 KB |
Output is correct |
59 |
Correct |
140 ms |
593420 KB |
Output is correct |
60 |
Correct |
134 ms |
597528 KB |
Output is correct |
61 |
Correct |
1403 ms |
840460 KB |
Output is correct |
62 |
Runtime error |
832 ms |
1048576 KB |
Execution killed with signal 9 |
63 |
Halted |
0 ms |
0 KB |
- |