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 ll long long
#define f first
#define s second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define ull unsigned ll
#define pb push_back
#define mp make_pair
using namespace std;
int n;
ll a[300001];
vector<ll>t[2000001];
void build(int v,int l,int r){
if(l==r){
t[v].pb(a[l]);
return;
}
int m=(l+r)/2;
build(2*v,l,m);
build(2*v+1,m+1,r);
t[v].resize((int)t[2*v].size()+(int)t[2*v+1].size());
merge(t[2*v].begin(),t[2*v].end(),t[2*v+1].begin(),t[2*v+1].end(),t[v].begin());
}
ll get(int v,int l,int r,int tl,int tr,ll val){
if(l==tl&&r==tr){
ll k=lower_bound(t[v].begin(),t[v].end(),val)-t[v].begin();
return k;
}
int tm=(tl+tr)/2;
if(r<=tm)return get(2*v,l,r,tl,tm,val);
if(l>tm)return get(2*v+1,l,r,tm+1,tr,val);
return get(2*v,l,tm,tl,tm,val)+get(2*v+1,tm+1,r,tm+1,tr,val);
}
ll ans=0;
int main(){
cin>>n;
for(int i=1;i<=n;i++)cin>>a[i];
build(1,1,n);
for(int i=2;i<n;i++){
ans+=get(1,1,i-1,1,n,a[i])*get(1,i+1,n,1,n,a[i]);
}
cout<<ans;
}
# | 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... |