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>
#define ll long long
#define F first
#define S second
#define N 300005
#define ii pair<int,int>
#define bit(i,j) ((i>>j)&1)
#define sz(i) (int)i.size()
#define endl '\n'
using namespace std;
int n;
int a[N];
namespace sub1
{
ll res;
int bit[N][2];
void upd(int id,int v,int k)
{
for(id;id<=n;id+=(id&(-id)))
bit[id][k]+=v;
}
int get(int id,int k)
{
int t=0;
for(id;id>0;id-=((id&(-id))))
t+=bit[id][k];
return t;
}
void compress()
{
vector<int>v;
for(int i=1;i<=n;i++)
v.push_back(a[i]);
sort(v.begin(),v.end());
v.resize(unique(v.begin(),v.end())-v.begin());
for(int i=1;i<=n;i++)
a[i]=lower_bound(v.begin(),v.end(),a[i])-v.begin()+1;
}
void solve()
{
compress();
for(int i=2;i<=n;i++)
upd(a[i],1,1);
upd(a[1],1,0);
for(int i=2;i<n;i++)
{
res+=1LL*get(a[i]-1,0)*get(a[i]-1,1);
upd(a[i],-1,1);
upd(a[i],1,0);
}
cout<<res;
}
}
main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cin>>n;
for(int i=1;i<=n;i++)
cin>>a[i];
sub1::solve();
}
Compilation message (stderr)
Mountains.cpp: In function 'void sub1::upd(int, int, int)':
Mountains.cpp:19:7: warning: statement has no effect [-Wunused-value]
19 | for(id;id<=n;id+=(id&(-id)))
| ^~
Mountains.cpp: In function 'int sub1::get(int, int)':
Mountains.cpp:25:7: warning: statement has no effect [-Wunused-value]
25 | for(id;id>0;id-=((id&(-id))))
| ^~
Mountains.cpp: At global scope:
Mountains.cpp:54:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
54 | main()
| ^~~~
# | 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... |