# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
329178 | oak | Mountains (NOI20_mountains) | C++14 | 561 ms | 28780 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>
#define si 300000
using namespace std;
int fw[si+1];
long long arr[si+1],db[si+1],sum[si+1];
void upd(int po,int val){
for(;po<=si;po+=(po&-po)){
fw[po]+=val;
}
}
int qry(int po){
int ret = 0;
for(;po>=1;po-=(po&-po)){
ret += fw[po];
}
return ret;
}
int main(){
int n,j,i;
scanf("%d",&n);
map<long long,int> mp;
int rl[n];
for(i=0;i<n;i++){
scanf("%lld",&arr[i]);
db[i] = arr[i];
}
sort(db,db+n);
int co = 1;
for(i=0;i<n;i++){
if(mp.find(db[i]) != mp.end())continue;
mp[db[i]] = co;
co++;
}
for(i=0;i<n;i++){
rl[i] = mp[arr[i]];
}
for(i=0;i<n;i++){
sum[i] = qry(rl[i]-1);
upd(rl[i],1);
}
long long ans = 0;
memset(fw,0,sizeof fw);
for(i=n-1;i>=0;i--){
sum[i] *= qry(rl[i]-1);
upd(rl[i],1);
ans += sum[i]*1ll;
}
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... |