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 |
1 |
Correct |
1 ms |
512 KB |
Output is correct |
2 |
Correct |
4 ms |
504 KB |
Output is correct |
3 |
Correct |
5 ms |
864 KB |
Output is correct |
4 |
Correct |
5 ms |
864 KB |
Output is correct |
5 |
Correct |
4 ms |
868 KB |
Output is correct |
6 |
Correct |
5 ms |
844 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
460 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
460 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
460 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
460 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |