Submission #798586

#TimeUsernameProblemLanguageResultExecution timeMemory
798586AndiRMountains (NOI20_mountains)C++14
100 / 100
770 ms44592 KiB
#include <iostream> #include <set> #include <map> using namespace std; typedef long long ll; const int Nmax=300000; ll n, v[Nmax]; set <ll> s; map <ll, int> m; int aib[Nmax+5]; ll sol[Nmax]; void aib_add(int pos){ for (int i=pos; i<=n; i+=i&-i) aib[i]++; } int aib_check(int pos){ int r=0; for (int i=pos; i>0; i-=i&-i) r+=aib[i]; return r; } int main() { cin>>n; for (int i=0; i<n; i++){ cin>>v[i]; s.insert(v[i]); } int ind=1; for (auto it=s.begin(); it!=s.end(); it++) m[*it]=ind++; for (int i=0; i<n; i++){ aib_add(m[v[i]]); sol[i]=aib_check(m[v[i]]-1); } for (int i=0; i<=n; i++) aib[i]=0; ll t=0; for (int i=n-1; i>=0; i--){ aib_add(m[v[i]]); t+=sol[i]*aib_check(m[v[i]]-1); } cout<<t; return 0; }
#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...