# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
928838 |
2024-02-17T06:37:34 Z |
knon0501 |
Rectangles (IOI19_rect) |
C++17 |
|
3510 ms |
1048576 KB |
#include "rect.h"
#include <bits/stdc++.h>
using namespace std;
vector<short> b[2505][2505];
vector<short> c[2505][2505];
vector<pair<short,short>> d[2505][2505];
vector<pair<short,short>> e[2505][2505];
short lef[2505][2505];
short rig[2505][2505];
short up[2505][2505];
short down[2505][2505];
long long v[2501*2501];
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<short>().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<short>().swap(c[i][j]);
}
}
int nn = 0;
for(int i = 1 ; i<n-1 ; i++){
for(int j=1 ; j<m-1 ; j++){
short x = lef[i][j];
short y = rig[i][j];
short z = up[i][j];
short w = down[i][j];
v[++nn]=x + 2501ll*y + 2501ll*2501ll*z+2501ll*2501*2501*w;
}
}
sort(v+1,v+nn+1);
for(int i=1 ; i<=nn ; i++){
if(v[i]==v[i-1])continue;
int x = v[i]%2501;
int y = v[i]/2501%2501;
int z = v[i]/2501/2501%2501;
int w = v[i]/2501/2501/2501%2501;
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(),(pair<short,short>){z+1,32767});
if(k== d[x+1][y-1].begin())continue;
if((--k)->second <w-1)continue;
auto t = upper_bound(e[z+1][w-1].begin(),e[z+1][w-1].end(),(pair<short,short>){x+1,32767});
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 |
159 ms |
599380 KB |
Output is correct |
2 |
Correct |
131 ms |
599380 KB |
Output is correct |
3 |
Correct |
132 ms |
599616 KB |
Output is correct |
4 |
Correct |
132 ms |
599344 KB |
Output is correct |
5 |
Correct |
131 ms |
599432 KB |
Output is correct |
6 |
Correct |
134 ms |
599528 KB |
Output is correct |
7 |
Correct |
131 ms |
599380 KB |
Output is correct |
8 |
Correct |
130 ms |
599588 KB |
Output is correct |
9 |
Correct |
136 ms |
599380 KB |
Output is correct |
10 |
Correct |
136 ms |
599588 KB |
Output is correct |
11 |
Correct |
133 ms |
599320 KB |
Output is correct |
12 |
Correct |
129 ms |
599388 KB |
Output is correct |
13 |
Correct |
135 ms |
591220 KB |
Output is correct |
14 |
Correct |
130 ms |
595324 KB |
Output is correct |
15 |
Correct |
130 ms |
599376 KB |
Output is correct |
16 |
Correct |
132 ms |
599380 KB |
Output is correct |
17 |
Correct |
132 ms |
591280 KB |
Output is correct |
18 |
Correct |
138 ms |
595204 KB |
Output is correct |
19 |
Correct |
144 ms |
599328 KB |
Output is correct |
20 |
Correct |
128 ms |
599380 KB |
Output is correct |
21 |
Correct |
132 ms |
595284 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
159 ms |
599380 KB |
Output is correct |
2 |
Correct |
131 ms |
599380 KB |
Output is correct |
3 |
Correct |
132 ms |
599616 KB |
Output is correct |
4 |
Correct |
132 ms |
599344 KB |
Output is correct |
5 |
Correct |
131 ms |
599432 KB |
Output is correct |
6 |
Correct |
134 ms |
599528 KB |
Output is correct |
7 |
Correct |
131 ms |
599380 KB |
Output is correct |
8 |
Correct |
130 ms |
599588 KB |
Output is correct |
9 |
Correct |
136 ms |
599380 KB |
Output is correct |
10 |
Correct |
136 ms |
599588 KB |
Output is correct |
11 |
Correct |
133 ms |
599320 KB |
Output is correct |
12 |
Correct |
129 ms |
599388 KB |
Output is correct |
13 |
Correct |
135 ms |
591220 KB |
Output is correct |
14 |
Correct |
130 ms |
595324 KB |
Output is correct |
15 |
Correct |
130 ms |
599376 KB |
Output is correct |
16 |
Correct |
132 ms |
599380 KB |
Output is correct |
17 |
Correct |
132 ms |
591280 KB |
Output is correct |
18 |
Correct |
138 ms |
595204 KB |
Output is correct |
19 |
Correct |
144 ms |
599328 KB |
Output is correct |
20 |
Correct |
128 ms |
599380 KB |
Output is correct |
21 |
Correct |
132 ms |
595284 KB |
Output is correct |
22 |
Correct |
139 ms |
599636 KB |
Output is correct |
23 |
Correct |
141 ms |
599636 KB |
Output is correct |
24 |
Correct |
133 ms |
599632 KB |
Output is correct |
25 |
Correct |
131 ms |
599840 KB |
Output is correct |
26 |
Correct |
133 ms |
599508 KB |
Output is correct |
27 |
Correct |
133 ms |
599468 KB |
Output is correct |
28 |
Correct |
131 ms |
599604 KB |
Output is correct |
29 |
Correct |
132 ms |
599636 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
159 ms |
599380 KB |
Output is correct |
2 |
Correct |
131 ms |
599380 KB |
Output is correct |
3 |
Correct |
132 ms |
599616 KB |
Output is correct |
4 |
Correct |
132 ms |
599344 KB |
Output is correct |
5 |
Correct |
131 ms |
599432 KB |
Output is correct |
6 |
Correct |
134 ms |
599528 KB |
Output is correct |
7 |
Correct |
131 ms |
599380 KB |
Output is correct |
8 |
Correct |
130 ms |
599588 KB |
Output is correct |
9 |
Correct |
136 ms |
599380 KB |
Output is correct |
10 |
Correct |
136 ms |
599588 KB |
Output is correct |
11 |
Correct |
133 ms |
599320 KB |
Output is correct |
12 |
Correct |
129 ms |
599388 KB |
Output is correct |
13 |
Correct |
135 ms |
591220 KB |
Output is correct |
14 |
Correct |
130 ms |
595324 KB |
Output is correct |
15 |
Correct |
130 ms |
599376 KB |
Output is correct |
16 |
Correct |
132 ms |
599380 KB |
Output is correct |
17 |
Correct |
139 ms |
599636 KB |
Output is correct |
18 |
Correct |
141 ms |
599636 KB |
Output is correct |
19 |
Correct |
133 ms |
599632 KB |
Output is correct |
20 |
Correct |
131 ms |
599840 KB |
Output is correct |
21 |
Correct |
133 ms |
599508 KB |
Output is correct |
22 |
Correct |
133 ms |
599468 KB |
Output is correct |
23 |
Correct |
131 ms |
599604 KB |
Output is correct |
24 |
Correct |
132 ms |
599636 KB |
Output is correct |
25 |
Correct |
132 ms |
591280 KB |
Output is correct |
26 |
Correct |
138 ms |
595204 KB |
Output is correct |
27 |
Correct |
144 ms |
599328 KB |
Output is correct |
28 |
Correct |
128 ms |
599380 KB |
Output is correct |
29 |
Correct |
132 ms |
595284 KB |
Output is correct |
30 |
Correct |
142 ms |
610316 KB |
Output is correct |
31 |
Correct |
136 ms |
610284 KB |
Output is correct |
32 |
Correct |
136 ms |
610420 KB |
Output is correct |
33 |
Correct |
144 ms |
610436 KB |
Output is correct |
34 |
Correct |
143 ms |
610600 KB |
Output is correct |
35 |
Runtime error |
2726 ms |
1048576 KB |
Execution killed with signal 9 |
36 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
159 ms |
599380 KB |
Output is correct |
2 |
Correct |
131 ms |
599380 KB |
Output is correct |
3 |
Correct |
132 ms |
599616 KB |
Output is correct |
4 |
Correct |
132 ms |
599344 KB |
Output is correct |
5 |
Correct |
131 ms |
599432 KB |
Output is correct |
6 |
Correct |
134 ms |
599528 KB |
Output is correct |
7 |
Correct |
131 ms |
599380 KB |
Output is correct |
8 |
Correct |
130 ms |
599588 KB |
Output is correct |
9 |
Correct |
136 ms |
599380 KB |
Output is correct |
10 |
Correct |
136 ms |
599588 KB |
Output is correct |
11 |
Correct |
133 ms |
599320 KB |
Output is correct |
12 |
Correct |
129 ms |
599388 KB |
Output is correct |
13 |
Correct |
135 ms |
591220 KB |
Output is correct |
14 |
Correct |
130 ms |
595324 KB |
Output is correct |
15 |
Correct |
130 ms |
599376 KB |
Output is correct |
16 |
Correct |
132 ms |
599380 KB |
Output is correct |
17 |
Correct |
139 ms |
599636 KB |
Output is correct |
18 |
Correct |
141 ms |
599636 KB |
Output is correct |
19 |
Correct |
133 ms |
599632 KB |
Output is correct |
20 |
Correct |
131 ms |
599840 KB |
Output is correct |
21 |
Correct |
133 ms |
599508 KB |
Output is correct |
22 |
Correct |
133 ms |
599468 KB |
Output is correct |
23 |
Correct |
131 ms |
599604 KB |
Output is correct |
24 |
Correct |
132 ms |
599636 KB |
Output is correct |
25 |
Correct |
142 ms |
610316 KB |
Output is correct |
26 |
Correct |
136 ms |
610284 KB |
Output is correct |
27 |
Correct |
136 ms |
610420 KB |
Output is correct |
28 |
Correct |
144 ms |
610436 KB |
Output is correct |
29 |
Correct |
143 ms |
610600 KB |
Output is correct |
30 |
Runtime error |
2726 ms |
1048576 KB |
Execution killed with signal 9 |
31 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
151 ms |
599464 KB |
Output is correct |
2 |
Correct |
140 ms |
599644 KB |
Output is correct |
3 |
Correct |
140 ms |
599380 KB |
Output is correct |
4 |
Correct |
127 ms |
595280 KB |
Output is correct |
5 |
Correct |
143 ms |
599664 KB |
Output is correct |
6 |
Correct |
149 ms |
599644 KB |
Output is correct |
7 |
Correct |
142 ms |
599532 KB |
Output is correct |
8 |
Correct |
145 ms |
599636 KB |
Output is correct |
9 |
Correct |
146 ms |
599632 KB |
Output is correct |
10 |
Correct |
139 ms |
595264 KB |
Output is correct |
11 |
Correct |
141 ms |
595448 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
132 ms |
591280 KB |
Output is correct |
2 |
Correct |
138 ms |
595204 KB |
Output is correct |
3 |
Correct |
144 ms |
599328 KB |
Output is correct |
4 |
Correct |
128 ms |
599380 KB |
Output is correct |
5 |
Correct |
132 ms |
595284 KB |
Output is correct |
6 |
Correct |
132 ms |
599380 KB |
Output is correct |
7 |
Correct |
608 ms |
674636 KB |
Output is correct |
8 |
Correct |
1186 ms |
747880 KB |
Output is correct |
9 |
Runtime error |
3510 ms |
1048576 KB |
Execution killed with signal 9 |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
159 ms |
599380 KB |
Output is correct |
2 |
Correct |
131 ms |
599380 KB |
Output is correct |
3 |
Correct |
132 ms |
599616 KB |
Output is correct |
4 |
Correct |
132 ms |
599344 KB |
Output is correct |
5 |
Correct |
131 ms |
599432 KB |
Output is correct |
6 |
Correct |
134 ms |
599528 KB |
Output is correct |
7 |
Correct |
131 ms |
599380 KB |
Output is correct |
8 |
Correct |
130 ms |
599588 KB |
Output is correct |
9 |
Correct |
136 ms |
599380 KB |
Output is correct |
10 |
Correct |
136 ms |
599588 KB |
Output is correct |
11 |
Correct |
133 ms |
599320 KB |
Output is correct |
12 |
Correct |
129 ms |
599388 KB |
Output is correct |
13 |
Correct |
135 ms |
591220 KB |
Output is correct |
14 |
Correct |
130 ms |
595324 KB |
Output is correct |
15 |
Correct |
130 ms |
599376 KB |
Output is correct |
16 |
Correct |
132 ms |
599380 KB |
Output is correct |
17 |
Correct |
139 ms |
599636 KB |
Output is correct |
18 |
Correct |
141 ms |
599636 KB |
Output is correct |
19 |
Correct |
133 ms |
599632 KB |
Output is correct |
20 |
Correct |
131 ms |
599840 KB |
Output is correct |
21 |
Correct |
133 ms |
599508 KB |
Output is correct |
22 |
Correct |
133 ms |
599468 KB |
Output is correct |
23 |
Correct |
131 ms |
599604 KB |
Output is correct |
24 |
Correct |
132 ms |
599636 KB |
Output is correct |
25 |
Correct |
142 ms |
610316 KB |
Output is correct |
26 |
Correct |
136 ms |
610284 KB |
Output is correct |
27 |
Correct |
136 ms |
610420 KB |
Output is correct |
28 |
Correct |
144 ms |
610436 KB |
Output is correct |
29 |
Correct |
143 ms |
610600 KB |
Output is correct |
30 |
Runtime error |
2726 ms |
1048576 KB |
Execution killed with signal 9 |
31 |
Halted |
0 ms |
0 KB |
- |