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>
using namespace std;
priority_queue<pair<long long, int> >pq;
long long ft[300005];
long long in1[300005];
long long in2[300005];
int cnt2 = 1;
int ls(int x){
return x & -x;
}
int query(int x){
long long sum = 0;
for(;x;x -= ls(x)){
sum += ft[x];
}
return sum;
}
void update(int x, int v){
for(;x<=cnt2;x += ls(x)){
ft[x] += v;
}
}
int main(){
int n;
cin >> n;
long long cnt = 0;
cnt2 = 1;
pair<long long, int> d[n+1];
long long c[n+1];
for(int i=1;i<=n;i++){
cin >> c[i];
}
for(int i = 1; i <= n; i++){
d[i].first = c[i];
d[i].second = i;
}
sort(d + 1, d + n + 1);
for(int i = 1; i <= n; i++){
if (i > 1 && d[i].first != d[i-1].first) cnt2++;
c[d[i].second] = cnt2;
}
for(int i=1;i<=n;i++){
in1[i] = query(c[i] - 1);
update(c[i], 1);
}
fill(ft, ft + n + 1, 0);
for(int i=n;i>=1;i--){
in2[i] = query(c[i]-1);
update(c[i], 1);
}
for(int i=0;i<n;i++){
cnt += in1[i]*in2[i];
}
cout << cnt;
}
# | 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... |