#include "rect.h"
#include<bits/stdc++.h>
using namespace std;
const int maxn=2500+10;
int all[maxn][maxn],vis[maxn][maxn],tp[maxn][maxn],n,m,dpp[maxn][maxn];
vector<int>alll[maxn][maxn],alld[maxn][maxn];
vector<pair<int,int>>allq[maxn][maxn];
vector<pair<int,int>>addy[maxn][maxn];
long long mainres=0;
struct fenwick{
int fn[maxn];
vector<int>allind;
void clear(){
for(auto x:allind){
while(x<maxn){
fn[x]=0;
x+=((-x)&x);
}
}
allind.shrink_to_fit();
allind.clear();
}
void add(int i,int w){
i++;
allind.push_back(i);
while(i<maxn){
fn[i]+=w;
i+=((-i)&i);
}
}
int pors(int l,int r){
int ret=0;
r++;
while(l>0){
ret-=fn[l];
l-=((-l)&l);
}
while(r>0){
ret+=fn[r];
r-=((-r)&r);
}
return ret;
}
}fen;
void pre(){
for(int i=1;i<=n;i++){
vector<pair<int,int>>allv;
for(int j=1;j<=m;j++){
while((int)allv.size()>0&&allv.back().first<all[i][j]){
alll[i][j].push_back(allv.back().second);
allv.pop_back();
}
if((int)allv.size()>0){
alll[i][j].push_back(allv.back().second);
}
if((int)allv.size()>0&&allv.back().first==all[i][j]){
allv.pop_back();
}
allv.push_back(make_pair(all[i][j],j));
}
}
for(int j=1;j<=m;j++){
vector<pair<int,int>>allv;
for(int i=n;i>=1;i--){
while((int)allv.size()>0&&allv.back().first<all[i][j]){
alld[i][j].push_back(allv.back().second);
allv.pop_back();
}
if((int)allv.size()>0){
alld[i][j].push_back(allv.back().second);
}
if((int)allv.size()>0&&allv.back().first==all[i][j]){
allv.pop_back();
}
allv.push_back(make_pair(all[i][j],i));
}
}
}
void solveq(){
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
sort(addy[i][j].begin(),addy[i][j].end());
sort(allq[i][j].begin(),allq[i][j].end());
// cout<<i<<" "<<j<<" :"<<endl;
// for(auto x:addy[i][j]){
// cout<<x.first<<" "<<x.second<<endl;
// }
// for(auto x:allq[i][j]){
// cout<<x.first<<" "<<x.second.first<<" "<<x.second.second<<endl;
// }
while((int)addy[i][j].size()>0&&(int)allq[i][j].size()>0){
if(addy[i][j].back().first>=allq[i][j].back().first){
fen.add(addy[i][j].back().second,1);
addy[i][j].pop_back();
}else{
mainres+=fen.pors(allq[i][j].back().second,j-2);
allq[i][j].pop_back();
}
}
while((int)allq[i][j].size()>0){
mainres+=fen.pors(allq[i][j].back().second,j-2);
allq[i][j].pop_back();
}
fen.clear();
}
}
}
void calq(){
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
for(auto x:alld[i][j]){
if(x<=i+1){
continue;
}
dpp[x][j]=dpp[x][j-1]+1;
allq[i+1][j+1].push_back(make_pair((x-i-1),j-dpp[x][j]));
}
}
for(int j=1;j<=m;j++){
for(auto x:alld[i][j]){
if(x<=i+1){
continue;
}
dpp[x][j]=0;
}
}
}
for(int j=1;j<=m;j++){
for(int i=n;i>=1;i--){
for(auto x:alll[i][j]){
if(x+1>=j){
continue;
}
dpp[i][x]=dpp[i+1][x]+1;
addy[i][j].push_back(make_pair(dpp[i][x],x));
}
}
for(int i=n;i>=1;i--){
for(auto x:alll[i][j]){
if(x+1>=j){
continue;
}
dpp[i][x]=0;
}
}
}
}
void solve(){
pre();
calq();
solveq();
}
long long count_rectangles(std::vector<std::vector<int> > a) {
n=a.size();
m=a[0].size();
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
all[i][j]=a[i-1][j-1];
}
}
solve();
return mainres;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
225 ms |
592208 KB |
Output is correct |
2 |
Correct |
244 ms |
592720 KB |
Output is correct |
3 |
Correct |
212 ms |
592468 KB |
Output is correct |
4 |
Correct |
217 ms |
592464 KB |
Output is correct |
5 |
Correct |
210 ms |
592416 KB |
Output is correct |
6 |
Correct |
212 ms |
592532 KB |
Output is correct |
7 |
Correct |
224 ms |
592464 KB |
Output is correct |
8 |
Correct |
209 ms |
592212 KB |
Output is correct |
9 |
Correct |
217 ms |
592468 KB |
Output is correct |
10 |
Correct |
210 ms |
592528 KB |
Output is correct |
11 |
Correct |
233 ms |
592428 KB |
Output is correct |
12 |
Correct |
219 ms |
592464 KB |
Output is correct |
13 |
Correct |
235 ms |
592208 KB |
Output is correct |
14 |
Correct |
211 ms |
592484 KB |
Output is correct |
15 |
Correct |
214 ms |
592208 KB |
Output is correct |
16 |
Correct |
214 ms |
592204 KB |
Output is correct |
17 |
Correct |
220 ms |
592088 KB |
Output is correct |
18 |
Correct |
226 ms |
592012 KB |
Output is correct |
19 |
Correct |
226 ms |
592468 KB |
Output is correct |
20 |
Correct |
214 ms |
592180 KB |
Output is correct |
21 |
Correct |
218 ms |
592252 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
225 ms |
592208 KB |
Output is correct |
2 |
Correct |
244 ms |
592720 KB |
Output is correct |
3 |
Correct |
212 ms |
592468 KB |
Output is correct |
4 |
Correct |
217 ms |
592464 KB |
Output is correct |
5 |
Correct |
210 ms |
592416 KB |
Output is correct |
6 |
Correct |
212 ms |
592532 KB |
Output is correct |
7 |
Correct |
224 ms |
592464 KB |
Output is correct |
8 |
Correct |
209 ms |
592212 KB |
Output is correct |
9 |
Correct |
217 ms |
592468 KB |
Output is correct |
10 |
Correct |
210 ms |
592528 KB |
Output is correct |
11 |
Correct |
233 ms |
592428 KB |
Output is correct |
12 |
Correct |
219 ms |
592464 KB |
Output is correct |
13 |
Correct |
235 ms |
592208 KB |
Output is correct |
14 |
Correct |
211 ms |
592484 KB |
Output is correct |
15 |
Correct |
214 ms |
592208 KB |
Output is correct |
16 |
Correct |
214 ms |
592204 KB |
Output is correct |
17 |
Correct |
220 ms |
592088 KB |
Output is correct |
18 |
Correct |
226 ms |
592012 KB |
Output is correct |
19 |
Correct |
226 ms |
592468 KB |
Output is correct |
20 |
Correct |
214 ms |
592180 KB |
Output is correct |
21 |
Correct |
218 ms |
592252 KB |
Output is correct |
22 |
Correct |
216 ms |
593540 KB |
Output is correct |
23 |
Correct |
223 ms |
593428 KB |
Output is correct |
24 |
Correct |
234 ms |
593748 KB |
Output is correct |
25 |
Correct |
219 ms |
593492 KB |
Output is correct |
26 |
Correct |
222 ms |
593376 KB |
Output is correct |
27 |
Correct |
214 ms |
593488 KB |
Output is correct |
28 |
Correct |
223 ms |
593488 KB |
Output is correct |
29 |
Correct |
225 ms |
593108 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
225 ms |
592208 KB |
Output is correct |
2 |
Correct |
244 ms |
592720 KB |
Output is correct |
3 |
Correct |
212 ms |
592468 KB |
Output is correct |
4 |
Correct |
217 ms |
592464 KB |
Output is correct |
5 |
Correct |
210 ms |
592416 KB |
Output is correct |
6 |
Correct |
212 ms |
592532 KB |
Output is correct |
7 |
Correct |
224 ms |
592464 KB |
Output is correct |
8 |
Correct |
209 ms |
592212 KB |
Output is correct |
9 |
Correct |
217 ms |
592468 KB |
Output is correct |
10 |
Correct |
210 ms |
592528 KB |
Output is correct |
11 |
Correct |
233 ms |
592428 KB |
Output is correct |
12 |
Correct |
219 ms |
592464 KB |
Output is correct |
13 |
Correct |
235 ms |
592208 KB |
Output is correct |
14 |
Correct |
211 ms |
592484 KB |
Output is correct |
15 |
Correct |
214 ms |
592208 KB |
Output is correct |
16 |
Correct |
214 ms |
592204 KB |
Output is correct |
17 |
Correct |
216 ms |
593540 KB |
Output is correct |
18 |
Correct |
223 ms |
593428 KB |
Output is correct |
19 |
Correct |
234 ms |
593748 KB |
Output is correct |
20 |
Correct |
219 ms |
593492 KB |
Output is correct |
21 |
Correct |
222 ms |
593376 KB |
Output is correct |
22 |
Correct |
214 ms |
593488 KB |
Output is correct |
23 |
Correct |
223 ms |
593488 KB |
Output is correct |
24 |
Correct |
225 ms |
593108 KB |
Output is correct |
25 |
Correct |
220 ms |
592088 KB |
Output is correct |
26 |
Correct |
226 ms |
592012 KB |
Output is correct |
27 |
Correct |
226 ms |
592468 KB |
Output is correct |
28 |
Correct |
214 ms |
592180 KB |
Output is correct |
29 |
Correct |
218 ms |
592252 KB |
Output is correct |
30 |
Correct |
227 ms |
598656 KB |
Output is correct |
31 |
Correct |
220 ms |
598608 KB |
Output is correct |
32 |
Correct |
222 ms |
598608 KB |
Output is correct |
33 |
Correct |
236 ms |
597584 KB |
Output is correct |
34 |
Correct |
218 ms |
598352 KB |
Output is correct |
35 |
Correct |
231 ms |
598356 KB |
Output is correct |
36 |
Correct |
231 ms |
598356 KB |
Output is correct |
37 |
Correct |
250 ms |
598272 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
225 ms |
592208 KB |
Output is correct |
2 |
Correct |
244 ms |
592720 KB |
Output is correct |
3 |
Correct |
212 ms |
592468 KB |
Output is correct |
4 |
Correct |
217 ms |
592464 KB |
Output is correct |
5 |
Correct |
210 ms |
592416 KB |
Output is correct |
6 |
Correct |
212 ms |
592532 KB |
Output is correct |
7 |
Correct |
224 ms |
592464 KB |
Output is correct |
8 |
Correct |
209 ms |
592212 KB |
Output is correct |
9 |
Correct |
217 ms |
592468 KB |
Output is correct |
10 |
Correct |
210 ms |
592528 KB |
Output is correct |
11 |
Correct |
233 ms |
592428 KB |
Output is correct |
12 |
Correct |
219 ms |
592464 KB |
Output is correct |
13 |
Correct |
235 ms |
592208 KB |
Output is correct |
14 |
Correct |
211 ms |
592484 KB |
Output is correct |
15 |
Correct |
214 ms |
592208 KB |
Output is correct |
16 |
Correct |
214 ms |
592204 KB |
Output is correct |
17 |
Correct |
216 ms |
593540 KB |
Output is correct |
18 |
Correct |
223 ms |
593428 KB |
Output is correct |
19 |
Correct |
234 ms |
593748 KB |
Output is correct |
20 |
Correct |
219 ms |
593492 KB |
Output is correct |
21 |
Correct |
222 ms |
593376 KB |
Output is correct |
22 |
Correct |
214 ms |
593488 KB |
Output is correct |
23 |
Correct |
223 ms |
593488 KB |
Output is correct |
24 |
Correct |
225 ms |
593108 KB |
Output is correct |
25 |
Correct |
227 ms |
598656 KB |
Output is correct |
26 |
Correct |
220 ms |
598608 KB |
Output is correct |
27 |
Correct |
222 ms |
598608 KB |
Output is correct |
28 |
Correct |
236 ms |
597584 KB |
Output is correct |
29 |
Correct |
218 ms |
598352 KB |
Output is correct |
30 |
Correct |
231 ms |
598356 KB |
Output is correct |
31 |
Correct |
231 ms |
598356 KB |
Output is correct |
32 |
Correct |
250 ms |
598272 KB |
Output is correct |
33 |
Correct |
220 ms |
592088 KB |
Output is correct |
34 |
Correct |
226 ms |
592012 KB |
Output is correct |
35 |
Correct |
226 ms |
592468 KB |
Output is correct |
36 |
Correct |
214 ms |
592180 KB |
Output is correct |
37 |
Correct |
218 ms |
592252 KB |
Output is correct |
38 |
Correct |
303 ms |
647248 KB |
Output is correct |
39 |
Correct |
333 ms |
649552 KB |
Output is correct |
40 |
Correct |
326 ms |
644644 KB |
Output is correct |
41 |
Correct |
325 ms |
646960 KB |
Output is correct |
42 |
Correct |
311 ms |
659796 KB |
Output is correct |
43 |
Correct |
325 ms |
659656 KB |
Output is correct |
44 |
Correct |
328 ms |
659796 KB |
Output is correct |
45 |
Correct |
320 ms |
655232 KB |
Output is correct |
46 |
Correct |
324 ms |
643820 KB |
Output is correct |
47 |
Correct |
345 ms |
646316 KB |
Output is correct |
48 |
Correct |
399 ms |
655024 KB |
Output is correct |
49 |
Correct |
396 ms |
655172 KB |
Output is correct |
50 |
Correct |
328 ms |
626516 KB |
Output is correct |
51 |
Correct |
326 ms |
623692 KB |
Output is correct |
52 |
Correct |
410 ms |
653656 KB |
Output is correct |
53 |
Correct |
400 ms |
653576 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
219 ms |
592820 KB |
Output is correct |
2 |
Correct |
225 ms |
592800 KB |
Output is correct |
3 |
Correct |
226 ms |
592552 KB |
Output is correct |
4 |
Correct |
216 ms |
592212 KB |
Output is correct |
5 |
Correct |
219 ms |
592724 KB |
Output is correct |
6 |
Correct |
225 ms |
592724 KB |
Output is correct |
7 |
Correct |
241 ms |
592720 KB |
Output is correct |
8 |
Correct |
243 ms |
592724 KB |
Output is correct |
9 |
Correct |
217 ms |
592720 KB |
Output is correct |
10 |
Correct |
205 ms |
592212 KB |
Output is correct |
11 |
Correct |
225 ms |
592464 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
220 ms |
592088 KB |
Output is correct |
2 |
Correct |
226 ms |
592012 KB |
Output is correct |
3 |
Correct |
226 ms |
592468 KB |
Output is correct |
4 |
Correct |
214 ms |
592180 KB |
Output is correct |
5 |
Correct |
218 ms |
592252 KB |
Output is correct |
6 |
Correct |
212 ms |
592096 KB |
Output is correct |
7 |
Correct |
944 ms |
862804 KB |
Output is correct |
8 |
Runtime error |
743 ms |
1048576 KB |
Execution killed with signal 9 |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
225 ms |
592208 KB |
Output is correct |
2 |
Correct |
244 ms |
592720 KB |
Output is correct |
3 |
Correct |
212 ms |
592468 KB |
Output is correct |
4 |
Correct |
217 ms |
592464 KB |
Output is correct |
5 |
Correct |
210 ms |
592416 KB |
Output is correct |
6 |
Correct |
212 ms |
592532 KB |
Output is correct |
7 |
Correct |
224 ms |
592464 KB |
Output is correct |
8 |
Correct |
209 ms |
592212 KB |
Output is correct |
9 |
Correct |
217 ms |
592468 KB |
Output is correct |
10 |
Correct |
210 ms |
592528 KB |
Output is correct |
11 |
Correct |
233 ms |
592428 KB |
Output is correct |
12 |
Correct |
219 ms |
592464 KB |
Output is correct |
13 |
Correct |
235 ms |
592208 KB |
Output is correct |
14 |
Correct |
211 ms |
592484 KB |
Output is correct |
15 |
Correct |
214 ms |
592208 KB |
Output is correct |
16 |
Correct |
214 ms |
592204 KB |
Output is correct |
17 |
Correct |
216 ms |
593540 KB |
Output is correct |
18 |
Correct |
223 ms |
593428 KB |
Output is correct |
19 |
Correct |
234 ms |
593748 KB |
Output is correct |
20 |
Correct |
219 ms |
593492 KB |
Output is correct |
21 |
Correct |
222 ms |
593376 KB |
Output is correct |
22 |
Correct |
214 ms |
593488 KB |
Output is correct |
23 |
Correct |
223 ms |
593488 KB |
Output is correct |
24 |
Correct |
225 ms |
593108 KB |
Output is correct |
25 |
Correct |
227 ms |
598656 KB |
Output is correct |
26 |
Correct |
220 ms |
598608 KB |
Output is correct |
27 |
Correct |
222 ms |
598608 KB |
Output is correct |
28 |
Correct |
236 ms |
597584 KB |
Output is correct |
29 |
Correct |
218 ms |
598352 KB |
Output is correct |
30 |
Correct |
231 ms |
598356 KB |
Output is correct |
31 |
Correct |
231 ms |
598356 KB |
Output is correct |
32 |
Correct |
250 ms |
598272 KB |
Output is correct |
33 |
Correct |
303 ms |
647248 KB |
Output is correct |
34 |
Correct |
333 ms |
649552 KB |
Output is correct |
35 |
Correct |
326 ms |
644644 KB |
Output is correct |
36 |
Correct |
325 ms |
646960 KB |
Output is correct |
37 |
Correct |
311 ms |
659796 KB |
Output is correct |
38 |
Correct |
325 ms |
659656 KB |
Output is correct |
39 |
Correct |
328 ms |
659796 KB |
Output is correct |
40 |
Correct |
320 ms |
655232 KB |
Output is correct |
41 |
Correct |
324 ms |
643820 KB |
Output is correct |
42 |
Correct |
345 ms |
646316 KB |
Output is correct |
43 |
Correct |
399 ms |
655024 KB |
Output is correct |
44 |
Correct |
396 ms |
655172 KB |
Output is correct |
45 |
Correct |
328 ms |
626516 KB |
Output is correct |
46 |
Correct |
326 ms |
623692 KB |
Output is correct |
47 |
Correct |
410 ms |
653656 KB |
Output is correct |
48 |
Correct |
400 ms |
653576 KB |
Output is correct |
49 |
Correct |
219 ms |
592820 KB |
Output is correct |
50 |
Correct |
225 ms |
592800 KB |
Output is correct |
51 |
Correct |
226 ms |
592552 KB |
Output is correct |
52 |
Correct |
216 ms |
592212 KB |
Output is correct |
53 |
Correct |
219 ms |
592724 KB |
Output is correct |
54 |
Correct |
225 ms |
592724 KB |
Output is correct |
55 |
Correct |
241 ms |
592720 KB |
Output is correct |
56 |
Correct |
243 ms |
592724 KB |
Output is correct |
57 |
Correct |
217 ms |
592720 KB |
Output is correct |
58 |
Correct |
205 ms |
592212 KB |
Output is correct |
59 |
Correct |
225 ms |
592464 KB |
Output is correct |
60 |
Correct |
212 ms |
592096 KB |
Output is correct |
61 |
Correct |
944 ms |
862804 KB |
Output is correct |
62 |
Runtime error |
743 ms |
1048576 KB |
Execution killed with signal 9 |
63 |
Halted |
0 ms |
0 KB |
- |