# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1092156 | khanhgng | Mountains (NOI20_mountains) | C++14 | 134 ms | 15556 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC optimize ("O3")
#include<bits/stdc++.h>
#define fi first
#define se second
#define ll long long
#define ld long double
#define pii pair<int,int>
#define SZ(x) ((int)(x.size()))
#define bit(i,x) ((x>>i)&1)
#define pb push_back
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define FORD(i,a,b) for(int i=(a);i>=(b);--i)
#define task "mountains"
#define int long long
using namespace std;
mt19937 rd(chrono::steady_clock::now().time_since_epoch().count());
ll Rand(ll l,ll r){assert(l<=r);return uniform_int_distribution<ll>(l,r)(rd);}
const int MAXn=5e5+7;
const int MOD=1e9+7;
const ll oo = 1e18;
const ll BASE=3137LL;
int n,a[MAXn],dp[MAXn],res;
struct FenwickTree{
int f[MAXn];
int N;
void init(int n){FOR(i,1,n)f[i]=0;N=n;}
void upd(int idx,int val){
for(idx;idx<=N;idx+=(idx&-idx)){
f[idx]+=val;
}
}
int get(int idx){
int ans=0;
for(idx;idx>=1;idx-=(idx&-idx)){
ans+=f[idx];
}
return ans;
}
}ft;
void solution(){
cin>>n;
vector<int>zip;
FOR(i,1,n)cin>>a[i],zip.pb(a[i]);
sort(zip.begin(),zip.end());
zip.resize(unique(zip.begin(),zip.end())-zip.begin());
FOR(i,1,n)a[i]=lower_bound(zip.begin(),zip.end(),a[i])-zip.begin()+1;
ft.init(n);
FOR(i,1,n){
dp[i]=ft.get(a[i]-1);
ft.upd(a[i],1);
}
ft.init(n);
FORD(i,n,1){
res+=dp[i]*ft.get(a[i]-1);
ft.upd(a[i],1);
}
cout<<res;
}
int32_t main(){
if(fopen(task".inp","r")){freopen(task".inp","r",stdin);freopen(task".out","w",stdout);}
ios_base::sync_with_stdio(0);cin.tie(0);
int ntest=1;//cin>>ntest;
while(ntest--){solution();}
cerr<<"\n"<<1.0*clock()/CLOCKS_PER_SEC<<"s ";
}
Compilation message (stderr)
# | 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... |