This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
using namespace std;
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
typedef long long LL;
typedef pair<int,int> pii;
#define pb push_back
#define mkp make_pair
#define F first
#define S second
#define iter(x) x.begin(),x.end()
#define REP(n) for (int __=n;__--;)
#define REP0(i,n) for (int i=0;i<n;++i)
#define REP1(i,n) for (int i=1;i<=n;++i)
const int maxn = 5e4+10, mod = 0;
const LL inf = 0;
void solve(){
int n, m;
int arr[maxn]{};
cin >> n >> m;
REP1(i, m) cin >> arr[i];
LL cnt = 0, ans = m; bool up = true;
REP1(i, m){
if ((arr[i] > arr[i-1]) ^ up){
ans += cnt * (cnt-1) / 2;
cnt = 2;
up = !up;
}
else ++cnt;
}
cout << ans + cnt * (cnt - 1) / 2;
}
int main(){
ios_base::sync_with_stdio(false); cin.tie(0);
solve();
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... |