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 int long long
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef long long ll;
typedef unsigned long long ull;
#define forinc(a,b,c) for(int a=b, _c=c; a<=_c; ++a)
#define fordec(a,b,c) for(int a=b, _c=c; a>=_c; --a)
#define forv(a,b) for(auto &a:b)
#define fasty ios_base::sync_with_stdio(false),cin.tie(0)
#define ar array
#define ii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define all(a) begin(a),end(a)
#define reset(f,x) memset(f,x,sizeof(f))
#define bit(x,i) (x>>(i-1)&1ll)
#define on(x,i) (x|(1ll<<(i-1)))
#define off(x,i) (x&~(1ll<<(i-1)))
const int N=1e5+5;
int n,a[N];
int it[N];
int f[N],g[N];
void upd(int i,int val){
for(; i<=n; i+=i&-i) it[i]+=val;
}
int get(int i){
int b=0;
for(; i; i-=i&-i) b+=it[i];
return b;
}
int32_t main(){
fasty;
cin>>n;
forinc(i,1,n) cin>>a[i];
vector<int> val;
forinc(i,1,n) val.pb(a[i]); sort(all(val)); val.erase(unique(all(val)), end(val));
forinc(i,1,n) a[i]=lower_bound(all(val),a[i])-begin(val)+1;
forinc(i,1,n){
f[i]=get(a[i]-1);
upd(a[i],1);
}
reset(it,0);
fordec(i,n,1){
g[i]=get(a[i]-1);
upd(a[i],1);
}
int ans=0;
forinc(i,1,n) ans+=g[i]*f[i];
cout<<ans<<'\n';
}
Compilation message (stderr)
Mountains.cpp: In function 'int32_t main()':
Mountains.cpp:7:23: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
7 | #define forinc(a,b,c) for(int a=b, _c=c; a<=_c; ++a)
| ^~~
Mountains.cpp:43:4: note: in expansion of macro 'forinc'
43 | forinc(i,1,n) val.pb(a[i]); sort(all(val)); val.erase(unique(all(val)), end(val));
| ^~~~~~
Mountains.cpp:43:32: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
43 | forinc(i,1,n) val.pb(a[i]); sort(all(val)); val.erase(unique(all(val)), end(val));
| ^~~~
# | 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... |