This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |