# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
586498 | krit3379 | Mountains (NOI20_mountains) | C++17 | 783 ms | 34076 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;
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#define N 300005
long long a[N],fen[N],l[N],r[N],ans;
map<long long,int> mp;
void upd(int x){
while(x<N){
fen[x]++;
x+=x&-x;
}
}
long long sol(int x){
long long ans=0;
while(x){
ans+=fen[x];
x-=x&-x;
}
return ans;
}
int main(){
int n,i;
scanf("%d",&n);
for(i=1;i<=n;i++)scanf("%lld",&a[i]),mp[a[i]];
i=0;
for(auto &[x,y]:mp)y=++i;
for(i=1;i<=n;i++){
l[i]=sol(mp[a[i]]);
upd(mp[a[i]]+1);
}
for(i=1;i<=n;i++)fen[i]=0;
for(i=n;i;i--){
r[i]=sol(mp[a[i]]);
upd(mp[a[i]]+1);
}
for(i=1;i<=n;i++)ans+=l[i]*r[i];
printf("%lld",ans);
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... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |