# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
295385 | beso123 | Mountains (NOI20_mountains) | C++14 | 533 ms | 20192 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 int long long
#define pii pair<int,int>
#define x first
#define y second
using namespace std;
const int N=300005;
int n,a[N],l[N],r[N];
int bit[N];
int GET(int i){
int sum=0;
while(i>=1){
sum+=bit[i];
i=i-(i&(-i));
}
return sum;
}
void UPD(int i,int val){
while(i<=n){
bit[i]+=val;
i=i+(i&(-i));
}
}
vector<pii> v;
main(){
cin>>n;
for(int k=1;k<=n;k++)
cin>>a[k];
for(int k=1;k<=n;k++){
v.push_back({a[k],k});
}
sort(v.begin(),v.end());
a[v[0].y]=1;
for(int k=1;k<v.size();k++){
a[v[k].y]=a[v[k-1].y];
if(v[k].x!=v[k-1].x)
a[v[k].y]++;
}
UPD(a[1],1);
for(int k=2;k<=n;k++){
l[k]=GET(a[k]-1);
UPD(a[k],1);
}
for(int k=1;k<=n;k++)
bit[k]=0;
UPD(a[n],1);
for(int k=n-1;k>=1;k--){
r[k]=GET(a[k]-1);
UPD(a[k],1);
}
int ans=0;
for(int k=1;k<=n;k++)
ans+=l[k]*r[k];
cout<<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... |