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;
typedef long long LL;
typedef pair<LL,LL> pii;
const LL MAXN=300005;
LL a[MAXN],bit[2][MAXN],MAX;
void update(LL now,LL val,LL no){
for(LL i=now;i<=MAX;i+=(i&(-i)))bit[no][i]+=val;
}
LL query(LL now,LL no){
LL ret=0;
if(now==0)return ret;
for(LL i=now;i>0;i-=(i&(-i)))ret+=bit[no][i];
return ret;
}
int main(){
ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
LL n;
cin >> n;
vector<pii> v;
for(LL i=1;i<=n;i++){
cin >> a[i];
v.push_back({a[i],i});
}
sort(v.begin(),v.end());
for(LL i=0;i<v.size();i++){
if(i==0 || v[i].first!=v[i-1].first)MAX++;
a[v[i].second]=MAX;
}
for(LL i=1;i<=n;i++)update(a[i],1,1);
LL ans=0;
for(LL i=1;i<=n;i++){
update(a[i],-1,1);
ans+=query(a[i]-1,0)*query(a[i]-1,1);
update(a[i],1,0);
}
cout << ans << '\n';
return 0;
}
Compilation message (stderr)
Mountains.cpp: In function 'int main()':
Mountains.cpp:30:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(LL i=0;i<v.size();i++){
~^~~~~~~~~
# | 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... |