# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
761995 | KN200711 | Mountains (NOI20_mountains) | C++14 | 363 ms | 34020 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.
# include <bits/stdc++.h>
# define ll long long
# define fi first
# define se second
using namespace std;
const int MXN = 3e5;
ll fen[300001];
map<ll, int> M;
void upd(int a) {
while(a <= MXN) {
fen[a]++;
a += a&(-a);
}
return;
}
ll qry(int a) {
int res = 0;
while(a > 0) {
res += fen[a];
a -= a&(-a);
}
return res;
}
int main() {
int N;
scanf("%d", &N);
vector<ll> arr(N);
for(int i=0;i<N;i++) {
scanf("%lld", &arr[i]);
M[arr[i]] = 1;
}
int cnt = 1;
for(auto p : M) {
M[p.fi] = cnt;
cnt++;
}
for(int i=0;i<N;i++) {
arr[i] = M[arr[i]];
// cout<<arr[i]<<endl;
}
vector<ll> pref(N);
for(int i=0;i<N;i++) {
pref[i] = qry(arr[i] - 1);
upd(arr[i]);
}
ll ans = 0ll;
for(int i=0;i<=MXN;i++) fen[i] = 0;
vector<ll> suff(N);
for(int i=N-1;i>=0;i--) {
suff[i] = qry(arr[i] - 1);
upd(arr[i]);
// cout<<pref[i]<<" "<<suff[i]<<endl;
ans += (1ll * pref[i]) * (1ll * suff[i]);
}
printf("%lld\n", ans);
return 0;
}
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... |