#include <bits/stdc++.h>
using namespace std;
#define ll long long
vector<vector<int>> arr;
ll H,W;
int main(){
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin>>H>>W;
arr = vector<vector<int>>(H,vector<int>(W));
ll ans = 0;
for(auto &i:arr)for(auto &j:i)cin>>j;
for(int i = 0;i<W;){
int pr = i;
int mn = arr[0][i];
while(pr<W&&arr[0][pr]<=mn)mn = arr[0][pr],pr++;
ll len = pr-i;
ans += len*(len+1)>>1;
i = pr;
}
for(int i = W-1;i>=0;){
int pr = i,mn = arr[0][i];
while(pr>=0&&arr[0][pr]<=mn)mn = arr[0][pr],pr--;
ll len = i-pr;
ans += len*(len-1)>>1;
i = pr;
}
cout<<ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
4 ms |
920 KB |
Output is correct |
3 |
Correct |
4 ms |
924 KB |
Output is correct |
4 |
Correct |
4 ms |
920 KB |
Output is correct |
5 |
Correct |
4 ms |
920 KB |
Output is correct |
6 |
Correct |
4 ms |
916 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
504 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
504 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
504 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
504 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |