#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 5;
struct fenwick_tree {
int f[N];
fenwick_tree() {
memset(f, 0, sizeof(f));
}
void upd(int i, int x) {
for (; i < N; i += i & -i) {
f[i] += x;
}
}
int get(int i) {
int r = 0;
for (; i > 0; i -= i & -i) {
r += f[i];
}
return r;
}
int get(int l, int r) {
return get(r) - get(l - 1);
}
};
int n;
long long H[N];
vector<long long> v;
fenwick_tree ft;
int l[N], r[N];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> H[i];
}
copy(H + 1, H + n + 1, back_inserter(v));
sort(v.begin(), v.end());
v.erase(unique(v.begin(), v.end()), v.end());
for (int i = 1; i <= n; i++) {
H[i] = lower_bound(v.begin(), v.end(), H[i]) - v.begin() + 1;
}
for (int i = 1; i <= n; i++) {
l[i] = ft.get(H[i] - 1);
ft.upd(H[i], +1);
}
memset(ft.f, 0, sizeof(ft.f));
for (int i = n; i >= 1; i--) {
r[i] = ft.get(H[i] - 1);
ft.upd(H[i], +1);
}
long long ans = 0;
for (int i = 1; i <= n; i++) {
ans += 1LL * l[i] * r[i];
}
cout << ans << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1624 KB |
Output is correct |
2 |
Correct |
66 ms |
14280 KB |
Output is correct |
3 |
Correct |
61 ms |
14216 KB |
Output is correct |
4 |
Correct |
58 ms |
14272 KB |
Output is correct |
5 |
Correct |
65 ms |
14276 KB |
Output is correct |
6 |
Correct |
59 ms |
14268 KB |
Output is correct |
7 |
Correct |
60 ms |
14272 KB |
Output is correct |
8 |
Correct |
60 ms |
14272 KB |
Output is correct |
9 |
Correct |
61 ms |
14280 KB |
Output is correct |
10 |
Correct |
67 ms |
14360 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
40 ms |
9160 KB |
Output is correct |
2 |
Correct |
40 ms |
9256 KB |
Output is correct |
3 |
Correct |
40 ms |
9296 KB |
Output is correct |
4 |
Correct |
41 ms |
9236 KB |
Output is correct |
5 |
Correct |
42 ms |
9356 KB |
Output is correct |
6 |
Correct |
39 ms |
9372 KB |
Output is correct |
7 |
Correct |
41 ms |
9152 KB |
Output is correct |
8 |
Correct |
36 ms |
9160 KB |
Output is correct |
9 |
Correct |
38 ms |
9384 KB |
Output is correct |
10 |
Correct |
1 ms |
1628 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
40 ms |
9160 KB |
Output is correct |
2 |
Correct |
40 ms |
9256 KB |
Output is correct |
3 |
Correct |
40 ms |
9296 KB |
Output is correct |
4 |
Correct |
41 ms |
9236 KB |
Output is correct |
5 |
Correct |
42 ms |
9356 KB |
Output is correct |
6 |
Correct |
39 ms |
9372 KB |
Output is correct |
7 |
Correct |
41 ms |
9152 KB |
Output is correct |
8 |
Correct |
36 ms |
9160 KB |
Output is correct |
9 |
Correct |
38 ms |
9384 KB |
Output is correct |
10 |
Correct |
1 ms |
1628 KB |
Output is correct |
11 |
Correct |
48 ms |
9408 KB |
Output is correct |
12 |
Correct |
49 ms |
9412 KB |
Output is correct |
13 |
Correct |
49 ms |
9424 KB |
Output is correct |
14 |
Correct |
48 ms |
9408 KB |
Output is correct |
15 |
Correct |
48 ms |
9516 KB |
Output is correct |
16 |
Correct |
49 ms |
9416 KB |
Output is correct |
17 |
Correct |
47 ms |
9404 KB |
Output is correct |
18 |
Correct |
33 ms |
9412 KB |
Output is correct |
19 |
Correct |
36 ms |
9412 KB |
Output is correct |
20 |
Correct |
1 ms |
1628 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1624 KB |
Output is correct |
2 |
Correct |
1 ms |
1628 KB |
Output is correct |
3 |
Correct |
1 ms |
1628 KB |
Output is correct |
4 |
Correct |
1 ms |
1628 KB |
Output is correct |
5 |
Correct |
1 ms |
1628 KB |
Output is correct |
6 |
Correct |
1 ms |
1628 KB |
Output is correct |
7 |
Correct |
1 ms |
1628 KB |
Output is correct |
8 |
Correct |
1 ms |
1628 KB |
Output is correct |
9 |
Correct |
1 ms |
1880 KB |
Output is correct |
10 |
Correct |
1 ms |
1624 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1624 KB |
Output is correct |
2 |
Correct |
1 ms |
1628 KB |
Output is correct |
3 |
Correct |
1 ms |
1628 KB |
Output is correct |
4 |
Correct |
1 ms |
1628 KB |
Output is correct |
5 |
Correct |
1 ms |
1628 KB |
Output is correct |
6 |
Correct |
1 ms |
1628 KB |
Output is correct |
7 |
Correct |
1 ms |
1628 KB |
Output is correct |
8 |
Correct |
1 ms |
1628 KB |
Output is correct |
9 |
Correct |
1 ms |
1880 KB |
Output is correct |
10 |
Correct |
1 ms |
1624 KB |
Output is correct |
11 |
Correct |
4 ms |
2140 KB |
Output is correct |
12 |
Correct |
4 ms |
2140 KB |
Output is correct |
13 |
Correct |
5 ms |
2396 KB |
Output is correct |
14 |
Correct |
4 ms |
2120 KB |
Output is correct |
15 |
Correct |
4 ms |
2140 KB |
Output is correct |
16 |
Correct |
4 ms |
2140 KB |
Output is correct |
17 |
Correct |
4 ms |
2148 KB |
Output is correct |
18 |
Correct |
4 ms |
2140 KB |
Output is correct |
19 |
Correct |
2 ms |
1908 KB |
Output is correct |
20 |
Correct |
1 ms |
1640 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
40 ms |
9160 KB |
Output is correct |
2 |
Correct |
40 ms |
9256 KB |
Output is correct |
3 |
Correct |
40 ms |
9296 KB |
Output is correct |
4 |
Correct |
41 ms |
9236 KB |
Output is correct |
5 |
Correct |
42 ms |
9356 KB |
Output is correct |
6 |
Correct |
39 ms |
9372 KB |
Output is correct |
7 |
Correct |
41 ms |
9152 KB |
Output is correct |
8 |
Correct |
36 ms |
9160 KB |
Output is correct |
9 |
Correct |
38 ms |
9384 KB |
Output is correct |
10 |
Correct |
1 ms |
1628 KB |
Output is correct |
11 |
Correct |
48 ms |
9408 KB |
Output is correct |
12 |
Correct |
49 ms |
9412 KB |
Output is correct |
13 |
Correct |
49 ms |
9424 KB |
Output is correct |
14 |
Correct |
48 ms |
9408 KB |
Output is correct |
15 |
Correct |
48 ms |
9516 KB |
Output is correct |
16 |
Correct |
49 ms |
9416 KB |
Output is correct |
17 |
Correct |
47 ms |
9404 KB |
Output is correct |
18 |
Correct |
33 ms |
9412 KB |
Output is correct |
19 |
Correct |
36 ms |
9412 KB |
Output is correct |
20 |
Correct |
1 ms |
1628 KB |
Output is correct |
21 |
Correct |
92 ms |
10508 KB |
Output is correct |
22 |
Correct |
91 ms |
10432 KB |
Output is correct |
23 |
Correct |
90 ms |
10428 KB |
Output is correct |
24 |
Correct |
105 ms |
10428 KB |
Output is correct |
25 |
Correct |
92 ms |
10288 KB |
Output is correct |
26 |
Correct |
85 ms |
10432 KB |
Output is correct |
27 |
Correct |
83 ms |
10428 KB |
Output is correct |
28 |
Correct |
42 ms |
10488 KB |
Output is correct |
29 |
Correct |
41 ms |
10440 KB |
Output is correct |
30 |
Correct |
1 ms |
1628 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1624 KB |
Output is correct |
2 |
Correct |
66 ms |
14280 KB |
Output is correct |
3 |
Correct |
61 ms |
14216 KB |
Output is correct |
4 |
Correct |
58 ms |
14272 KB |
Output is correct |
5 |
Correct |
65 ms |
14276 KB |
Output is correct |
6 |
Correct |
59 ms |
14268 KB |
Output is correct |
7 |
Correct |
60 ms |
14272 KB |
Output is correct |
8 |
Correct |
60 ms |
14272 KB |
Output is correct |
9 |
Correct |
61 ms |
14280 KB |
Output is correct |
10 |
Correct |
67 ms |
14360 KB |
Output is correct |
11 |
Correct |
40 ms |
9160 KB |
Output is correct |
12 |
Correct |
40 ms |
9256 KB |
Output is correct |
13 |
Correct |
40 ms |
9296 KB |
Output is correct |
14 |
Correct |
41 ms |
9236 KB |
Output is correct |
15 |
Correct |
42 ms |
9356 KB |
Output is correct |
16 |
Correct |
39 ms |
9372 KB |
Output is correct |
17 |
Correct |
41 ms |
9152 KB |
Output is correct |
18 |
Correct |
36 ms |
9160 KB |
Output is correct |
19 |
Correct |
38 ms |
9384 KB |
Output is correct |
20 |
Correct |
1 ms |
1628 KB |
Output is correct |
21 |
Correct |
48 ms |
9408 KB |
Output is correct |
22 |
Correct |
49 ms |
9412 KB |
Output is correct |
23 |
Correct |
49 ms |
9424 KB |
Output is correct |
24 |
Correct |
48 ms |
9408 KB |
Output is correct |
25 |
Correct |
48 ms |
9516 KB |
Output is correct |
26 |
Correct |
49 ms |
9416 KB |
Output is correct |
27 |
Correct |
47 ms |
9404 KB |
Output is correct |
28 |
Correct |
33 ms |
9412 KB |
Output is correct |
29 |
Correct |
36 ms |
9412 KB |
Output is correct |
30 |
Correct |
1 ms |
1628 KB |
Output is correct |
31 |
Correct |
1 ms |
1624 KB |
Output is correct |
32 |
Correct |
1 ms |
1628 KB |
Output is correct |
33 |
Correct |
1 ms |
1628 KB |
Output is correct |
34 |
Correct |
1 ms |
1628 KB |
Output is correct |
35 |
Correct |
1 ms |
1628 KB |
Output is correct |
36 |
Correct |
1 ms |
1628 KB |
Output is correct |
37 |
Correct |
1 ms |
1628 KB |
Output is correct |
38 |
Correct |
1 ms |
1628 KB |
Output is correct |
39 |
Correct |
1 ms |
1880 KB |
Output is correct |
40 |
Correct |
1 ms |
1624 KB |
Output is correct |
41 |
Correct |
4 ms |
2140 KB |
Output is correct |
42 |
Correct |
4 ms |
2140 KB |
Output is correct |
43 |
Correct |
5 ms |
2396 KB |
Output is correct |
44 |
Correct |
4 ms |
2120 KB |
Output is correct |
45 |
Correct |
4 ms |
2140 KB |
Output is correct |
46 |
Correct |
4 ms |
2140 KB |
Output is correct |
47 |
Correct |
4 ms |
2148 KB |
Output is correct |
48 |
Correct |
4 ms |
2140 KB |
Output is correct |
49 |
Correct |
2 ms |
1908 KB |
Output is correct |
50 |
Correct |
1 ms |
1640 KB |
Output is correct |
51 |
Correct |
92 ms |
10508 KB |
Output is correct |
52 |
Correct |
91 ms |
10432 KB |
Output is correct |
53 |
Correct |
90 ms |
10428 KB |
Output is correct |
54 |
Correct |
105 ms |
10428 KB |
Output is correct |
55 |
Correct |
92 ms |
10288 KB |
Output is correct |
56 |
Correct |
85 ms |
10432 KB |
Output is correct |
57 |
Correct |
83 ms |
10428 KB |
Output is correct |
58 |
Correct |
42 ms |
10488 KB |
Output is correct |
59 |
Correct |
41 ms |
10440 KB |
Output is correct |
60 |
Correct |
1 ms |
1628 KB |
Output is correct |
61 |
Correct |
107 ms |
14272 KB |
Output is correct |
62 |
Correct |
121 ms |
14160 KB |
Output is correct |
63 |
Correct |
117 ms |
14268 KB |
Output is correct |
64 |
Correct |
121 ms |
14272 KB |
Output is correct |
65 |
Correct |
115 ms |
14272 KB |
Output is correct |
66 |
Correct |
111 ms |
14308 KB |
Output is correct |
67 |
Correct |
110 ms |
14148 KB |
Output is correct |
68 |
Correct |
105 ms |
14272 KB |
Output is correct |
69 |
Correct |
92 ms |
10432 KB |
Output is correct |
70 |
Correct |
1 ms |
1628 KB |
Output is correct |