# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
329920 | M_W | Mountains (NOI20_mountains) | C++14 | 362 ms | 32736 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;
map<long long, int> mp;
long long a[300300], b[300300];
int fwt[300300];
void add(int v){
for(;v <= 300300; v += (v & -v))
fwt[v]++;
}
int query(int v){
int ret = 0;
for(;v > 0; v -= (v & -v)){
ret += fwt[v];
}
return ret;
}
int main(){
int N;
scanf("%d", &N);
for(int i = 0; i < N; i++){
scanf("%lld", &a[i]);
b[i] = a[i];
}
sort(a, a + N);
int k = 1;
for(int i = 0; i < N; i++){
if(mp[a[i]] == 0) mp[a[i]] = k++;
}
vector<int> l;
for(int i = 0; i < N; i++){
l.push_back(query(mp[b[i]] - 1));
add(mp[b[i]]);
}
memset(fwt, 0, sizeof fwt);
long long ans = 0;
for(int i = N - 1; i >= 0; i--){
ans += (query(mp[b[i]] - 1) * l[i]) * 1ll;
add(mp[b[i]]);
}
printf("%lld", ans);
}
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... |