Submission #285592

#TimeUsernameProblemLanguageResultExecution timeMemory
285592Ronin13Mountains (NOI20_mountains)C++14
24 / 100
809 ms67864 KiB
#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; int a[300001]; vector<int>t[1200001]; 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,int 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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...