# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
329141 | M_W | Mountains (NOI20_mountains) | C++14 | 2095 ms | 7204 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 <bits/stdc++.h>
using namespace std;
int h[300300];
vector<int> v;
int main(){
int N;
vector<long long> cnt;
scanf("%d", &N);
for(int i = 0; i < N; i++){
scanf("%d", &h[i]);
if(i == 0){
v.push_back(h[i]);
cnt.push_back(0);
continue;
}
auto it = upper_bound(v.begin(), v.end(), h[i]);
v.insert(it, h[i]);
cnt.push_back(lower_bound(v.begin(), v.end(), h[i]) - v.begin());
}
v.clear();
long long sum = 0;
for(int i = N - 1; i >= 0; i--){
if(i == 0){
v.push_back(h[i]);
cnt.push_back(0);
continue;
}
auto it = upper_bound(v.begin(), v.end(), h[i]);
v.insert(it, h[i]);
sum += cnt[i] * 1ll * (lower_bound(v.begin(), v.end(), h[i]) - v.begin()) * 1ll;
}
printf("%lld", sum);
}
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... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |