@@ -56,50 +56,50 @@ int main() {
56
56
for (int i = 1; i <= n; i++) { lst2[n + 1 ][i ] = n + 2; }
57
57
for (char i = 'z'; i >= 'a'; i--) {
58
58
for (int row = 1; row <= n; row++) {
59
- int cnt = 0;
59
+ int stackSize = 0;
60
60
for (int col = 1; col <= n; col++) {
61
61
if (mat[row ][col ] >= i) {
62
62
lst[row ][col ] = row;
63
63
} else {
64
64
lst[row ][col ] = lst[row - 1 ][col ];
65
65
}
66
- while (cnt && lst[row - 1 ][col ] >= lst[row ][d [cnt ]]) { --cnt ; }
66
+ while (stackSize && lst[row - 1 ][col ] >= lst[row ][d [stackSize ]]) { --stackSize ; }
67
67
if (mat[row ][col ] == i) {
68
- ans += cnt ;
69
- if (cnt && d[1 ] == col) { --ans ; }
68
+ ans += stackSize ;
69
+ if (stackSize && d[1 ] == col) { --stackSize ; }
70
70
}
71
- while (cnt && lst[row ][col ] >= lst[row ][d [cnt ]]) { --cnt ; }
71
+ while (stackSize && lst[row ][col ] >= lst[row ][d [stackSize ]]) { --stackSize ; }
72
72
if (lst[row ][col ] <= (row - 1 ) && lst [row ][col ] != 0 ) {
73
- d [++ cnt ] = col ;
73
+ d [++ stackSize ] = col ;
74
74
}
75
75
}
76
76
}
77
77
78
78
for (int row = n ; row >= 1 ; row --) {
79
- int cnt = 0 ;
79
+ int stackSize = 0 ;
80
80
int hm = 0 ;
81
81
for (int col = n ; col >= 1 ; col --) {
82
82
if (mat [row ][col ] >= i ) {
83
83
lst2 [row ][col ] = row ;
84
84
} else {
85
85
lst2 [row ][col ] = lst2 [row + 1 ][col ];
86
86
}
87
- while (cnt && lst2 [row + 1 ][col ] <= lst2 [row ][d [cnt ]]) {
88
- if (mat [lst2 [row ][d [cnt ]]][d [cnt ]] == i ) { hm -- ; }
89
- cnt -- ;
87
+ while (stackSize && lst2 [row + 1 ][col ] <= lst2 [row ][d [stackSize ]]) {
88
+ if (mat [lst2 [row ][d [stackSize ]]][d [stackSize ]] == i ) { hm -- ; }
89
+ stackSize -- ;
90
90
}
91
91
if (mat [row ][col ] == i ) {
92
- ans += cnt ;
92
+ ans += stackSize ;
93
93
ans -= hm ;
94
- if (cnt && d [cnt ] == col ) { ans -- ; }
94
+ if (stackSize && d [stackSize ] == col ) { ans -- ; }
95
95
}
96
- while (cnt && lst2 [row ][col ] <= lst2 [row ][d [cnt ]]) {
97
- if (mat [lst2 [row ][d [cnt ]]][d [cnt ]] == i ) { hm -- ; }
98
- cnt -- ;
96
+ while (stackSize && lst2 [row ][col ] <= lst2 [row ][d [stackSize ]]) {
97
+ if (mat [lst2 [row ][d [stackSize ]]][d [stackSize ]] == i ) { hm -- ; }
98
+ stackSize -- ;
99
99
}
100
100
if (lst2 [row ][col ] >= (row + 1 ) && lst2 [row ][col ] != (n + 2 )) {
101
101
if (mat [lst2 [row ][col ]][col ] == i ) { hm ++ ; }
102
- d [++ cnt ] = col ;
102
+ d [++ stackSize ] = col ;
103
103
}
104
104
}
105
105
}
0 commit comments