# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
886600 | dubabuba | Sandcastle 2 (JOI22_ho_t5) | C++14 | 0 ms | 348 KiB |
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 <iostream>
#include <vector>
using namespace std;
const int mxn = 1e5 + 10;
int n, m, a[mxn];
int main() {
cin >> n >> m;
if(n > 1) return 1;
for(int i = 0; i < m; i++)
cin >> a[i];
vector<int> sus = {0};
for(int i = 1; i < m - 1; i++) {
if(a[i] > a[i - 1] && a[i] > a[i + 1]) sus.push_back(i);
if(a[i] < a[i - 1] && a[i] < a[i + 1]) sus.push_back(i);
}
sus.push_back(m - 1);
int ans = 0;
for(int i = 1; i < sus.size(); i++) {
int l = sus[i - 1];
int r = sus[i];
ans += (r - l + 1) * (r - l + 2) / 2;
}
cout << ans - sus.size() << '\n';
return 0;
}
Compilation message (stderr)
# | 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... |