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>
typedef long long ll;
#define fastio cin.tie(0), cout.tie(0), ios::sync_with_stdio(0);
using namespace std;
int main(){
//fastio
int h, w;
cin >> h >> w;
vector<int> val;
vector<vector<int>> a(h, vector<int> (w));
for(int i=0; i<h; i++){
for(int j=0; j<w; j++){
cin >> a[i][j];
val.push_back(a[i][j]);
}
}
sort(val.begin(), val.end());
for(int i=0; i<h; i++){
for(int j=0; j<w; j++)
a[i][j] = lower_bound(val.begin(), val.end(), a[i][j])-val.begin();
}
if(h>1) return 0;
ll ans = 0;
int cb = 0;
for(int j=0; j<w; j++){
if(j && a[0][j-1]<a[0][j]) cb++;
else cb = 1;
ans += cb;
}
for(int j=0; j<w; j++){
if(j && a[0][j-1]-1>a[0][j]){
cb++;
ans += cb;
}
else cb = 0;
}
cout << ans << '\n';
return 0;
}
# | 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... |