#include <bits/stdc++.h>
#pragma GCC optimize("O3", "unroll-loops")
using namespace std;
using ll = long long;
const int N = 300'000 + 10;
struct FenWick {
int n_node = 0;
vector<int> tree = {};
void resize(int n) { n_node = n; tree.resize(n + 10, 0); }
FenWick() {};
FenWick(int n) { this -> resize(n); };
void Update(int idx, int val) {
for( ; idx <= n_node; idx += (idx & - idx)) tree[idx] += val;
return;
}
int Query(int idx) {
int res = 0;
for( ; idx > 0; idx -= (idx & - idx)) res += tree[idx];
return res;
}
int Sum_to(int l, int r) {
if(l > r) return 0;
return Query(r) - Query(l - 1);
}
int kth(int val) {
int res = 0, s = 0;
for(int mask = 30; mask >= 0; -- mask) {
int nxt = res | (1 << mask);
if(nxt < n_node && s + tree[nxt] < val) {
res = nxt;
s += tree[nxt];
}
}
++ res; return res;
}
void reset(int idx) {
for ( ; idx <= n_node; idx += (idx & - idx)) tree[idx] = 0;
return;
}
};
int n;
ll a[N];
int L[N], R[N];
void compress() {
vector<int> Pos = {};
for (int i = 1; i <= n; ++ i) {
Pos.push_back(a[i]);
}
sort(Pos.begin(), Pos.end());
Pos.resize(unique(Pos.begin(), Pos.end()) - Pos.begin());
for (int i = 1; i <= n; ++ i) {
a[i] = lower_bound(Pos.begin(), Pos.end(), a[i]) - Pos.begin() + 1;
}
}
void calc(int cnt[]) {
FenWick bit(n);
for (int i = 1; i <= n; ++ i) {
cnt[i] = bit.Query(a[i]);
bit.Update(a[i] + 1, 1);
}
}
int32_t main() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(nullptr); std::cout.tie(nullptr);
cin >> n;
for (int i = 1; i <= n; ++ i) cin >> a[i];
compress();
calc(L);
reverse(a + 1, a + 1 + n);
calc(R);
ll res = 0;
for (int i = 1; i <= n; ++ i) res += 1ll * L[i] * R[n - i + 1];
cout << res;
return (0 ^ 0);
}
/// Code by vuavisao
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
67 ms |
11796 KB |
Output is correct |
3 |
Correct |
67 ms |
11816 KB |
Output is correct |
4 |
Correct |
64 ms |
11808 KB |
Output is correct |
5 |
Correct |
68 ms |
12076 KB |
Output is correct |
6 |
Correct |
65 ms |
11828 KB |
Output is correct |
7 |
Correct |
67 ms |
11844 KB |
Output is correct |
8 |
Correct |
75 ms |
11828 KB |
Output is correct |
9 |
Correct |
57 ms |
11828 KB |
Output is correct |
10 |
Correct |
57 ms |
11816 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
43 ms |
6708 KB |
Output is correct |
2 |
Correct |
42 ms |
6708 KB |
Output is correct |
3 |
Correct |
47 ms |
6688 KB |
Output is correct |
4 |
Correct |
48 ms |
6712 KB |
Output is correct |
5 |
Correct |
46 ms |
6712 KB |
Output is correct |
6 |
Correct |
41 ms |
6716 KB |
Output is correct |
7 |
Correct |
41 ms |
6736 KB |
Output is correct |
8 |
Correct |
36 ms |
6768 KB |
Output is correct |
9 |
Correct |
34 ms |
6768 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
43 ms |
6708 KB |
Output is correct |
2 |
Correct |
42 ms |
6708 KB |
Output is correct |
3 |
Correct |
47 ms |
6688 KB |
Output is correct |
4 |
Correct |
48 ms |
6712 KB |
Output is correct |
5 |
Correct |
46 ms |
6712 KB |
Output is correct |
6 |
Correct |
41 ms |
6716 KB |
Output is correct |
7 |
Correct |
41 ms |
6736 KB |
Output is correct |
8 |
Correct |
36 ms |
6768 KB |
Output is correct |
9 |
Correct |
34 ms |
6768 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
48 ms |
7132 KB |
Output is correct |
12 |
Correct |
49 ms |
6968 KB |
Output is correct |
13 |
Correct |
48 ms |
6968 KB |
Output is correct |
14 |
Correct |
48 ms |
6968 KB |
Output is correct |
15 |
Correct |
49 ms |
6964 KB |
Output is correct |
16 |
Correct |
51 ms |
7176 KB |
Output is correct |
17 |
Correct |
52 ms |
6960 KB |
Output is correct |
18 |
Correct |
32 ms |
6964 KB |
Output is correct |
19 |
Correct |
34 ms |
6948 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
43 ms |
6708 KB |
Output is correct |
2 |
Correct |
42 ms |
6708 KB |
Output is correct |
3 |
Correct |
47 ms |
6688 KB |
Output is correct |
4 |
Correct |
48 ms |
6712 KB |
Output is correct |
5 |
Correct |
46 ms |
6712 KB |
Output is correct |
6 |
Correct |
41 ms |
6716 KB |
Output is correct |
7 |
Correct |
41 ms |
6736 KB |
Output is correct |
8 |
Correct |
36 ms |
6768 KB |
Output is correct |
9 |
Correct |
34 ms |
6768 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
48 ms |
7132 KB |
Output is correct |
12 |
Correct |
49 ms |
6968 KB |
Output is correct |
13 |
Correct |
48 ms |
6968 KB |
Output is correct |
14 |
Correct |
48 ms |
6968 KB |
Output is correct |
15 |
Correct |
49 ms |
6964 KB |
Output is correct |
16 |
Correct |
51 ms |
7176 KB |
Output is correct |
17 |
Correct |
52 ms |
6960 KB |
Output is correct |
18 |
Correct |
32 ms |
6964 KB |
Output is correct |
19 |
Correct |
34 ms |
6948 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
95 ms |
7984 KB |
Output is correct |
22 |
Correct |
106 ms |
7988 KB |
Output is correct |
23 |
Correct |
93 ms |
7996 KB |
Output is correct |
24 |
Correct |
91 ms |
7988 KB |
Output is correct |
25 |
Correct |
92 ms |
7972 KB |
Output is correct |
26 |
Correct |
95 ms |
7984 KB |
Output is correct |
27 |
Correct |
92 ms |
7984 KB |
Output is correct |
28 |
Correct |
50 ms |
7820 KB |
Output is correct |
29 |
Correct |
43 ms |
7824 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
67 ms |
11796 KB |
Output is correct |
3 |
Correct |
67 ms |
11816 KB |
Output is correct |
4 |
Correct |
64 ms |
11808 KB |
Output is correct |
5 |
Correct |
68 ms |
12076 KB |
Output is correct |
6 |
Correct |
65 ms |
11828 KB |
Output is correct |
7 |
Correct |
67 ms |
11844 KB |
Output is correct |
8 |
Correct |
75 ms |
11828 KB |
Output is correct |
9 |
Correct |
57 ms |
11828 KB |
Output is correct |
10 |
Correct |
57 ms |
11816 KB |
Output is correct |
11 |
Correct |
43 ms |
6708 KB |
Output is correct |
12 |
Correct |
42 ms |
6708 KB |
Output is correct |
13 |
Correct |
47 ms |
6688 KB |
Output is correct |
14 |
Correct |
48 ms |
6712 KB |
Output is correct |
15 |
Correct |
46 ms |
6712 KB |
Output is correct |
16 |
Correct |
41 ms |
6716 KB |
Output is correct |
17 |
Correct |
41 ms |
6736 KB |
Output is correct |
18 |
Correct |
36 ms |
6768 KB |
Output is correct |
19 |
Correct |
34 ms |
6768 KB |
Output is correct |
20 |
Correct |
0 ms |
344 KB |
Output is correct |
21 |
Correct |
48 ms |
7132 KB |
Output is correct |
22 |
Correct |
49 ms |
6968 KB |
Output is correct |
23 |
Correct |
48 ms |
6968 KB |
Output is correct |
24 |
Correct |
48 ms |
6968 KB |
Output is correct |
25 |
Correct |
49 ms |
6964 KB |
Output is correct |
26 |
Correct |
51 ms |
7176 KB |
Output is correct |
27 |
Correct |
52 ms |
6960 KB |
Output is correct |
28 |
Correct |
32 ms |
6964 KB |
Output is correct |
29 |
Correct |
34 ms |
6948 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
32 |
Halted |
0 ms |
0 KB |
- |