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 <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int n;
long long low[300001],high[300001];
long long ans = 0;
long long a[300001];
void ulow(int x){
for(;x<=n;x += x&-x){
low[x]++;
}
}
long long glow(int x){
long long s = 0;
for(;x;x -= x&-x){
s += low[x];
}
return s;
}
void uhigh(int x,long long v){
for(;x;x -= x&-x){
high[x]+=v;
}
}
long long ghigh(int x){
long long s = 0;
for(;x<=n;x += x&-x){
s += high[x];
}
return s;
}
int main(int argc,const char** argv){
cin >> n;
for(int i = 0;i < n;i++) cin >> a[i];
vector<long long> r(a,a+n);
sort(r.begin(),r.end());
r.resize(unique(r.begin(),r.end()) - r.begin());
for(int i = 0;i < n;i++) a[i] = lower_bound(r.begin(),r.end(),a[i]) - r.begin() + 1;
for(int i = 0;i < n;i++){
long long u = glow(a[i]-1);
ulow(a[i]);
long long v = ghigh(a[i]+1);
uhigh(a[i],u);
ans += v;
}
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... |