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;
#define fi first
#define se second
constexpr int MAXN = 1 << 19;
int fw[MAXN];
void add(int p, int v) {
for (p++; p < MAXN; p += p & -p) {
fw[p] += v;
}
}
int sum(int p) {
int r = 0;
for (p++; p > 0; p -= p & -p) {
r += fw[p];
}
return r;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int N;
cin >> N;
vector<int> V(N);
map<int, int> M;
for (int& i : V) {
cin >> i;
M[i] = 0;
}
int x = 0;
for (auto& p : M) {
p.second = x++;
}
for (int& i : V) {
i = M[i];
}
vector<int> L(N), R(N);
for (int i = 0; i < N; i++) {
L[i] = sum(V[i] - 1);
add(V[i], 1);
}
fill(fw, fw + MAXN, 0);
for (int i = N - 1; i >= 0; i--) {
R[i] = sum(V[i] - 1);
add(V[i], 1);
}
ll res = 0;
for (int i = 0; i < N; i++) {
res += 1ll * L[i] * R[i];
}
cout << res << endl;
return 0;
}
# | 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... |