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;
#define ll long long
const int nx=3e5+5;
ll n, h[nx], t, dp[nx], res;
vector<ll> v;
struct fenwick
{
ll d[nx];
void add(int idx)
{
for (int i=idx; i<nx; i+=(i&-i)) d[i]++;
}
ll query(int idx)
{
ll res=0;
for (int i=idx; i>0; i-=(i&-i)) res+=d[i];
return res;
}
} l, r;
int main()
{
cin.tie(NULL)->sync_with_stdio(false);
cin>>n;
for (int i=1; i<=n; i++) cin>>h[i], v.push_back(h[i]);
sort(v.begin(), v.end());
for (int i=1; i<=n; i++)
{
int idx=lower_bound(v.begin(), v.end(), h[i])-v.begin()+1;
dp[i]=l.query(idx-1);
cout<<i<<' '<<dp[i]<<'\n';
l.add(idx);
}
for (int i=n; i>=1; i--)
{
int idx=lower_bound(v.begin(), v.end(), h[i])-v.begin()+1;
res+=dp[i]*r.query(idx-1);
r.add(idx);
}
cout<<res;
}
# | 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... |