#include <iostream>
#include <vector>
#include <algorithm>
typedef long long i64;
using namespace std;
const int N = 3e5 + 5;
i64 a [N];
struct FenwickTree {
vector<int> bit;
const int N;
FenwickTree (int n) : N (n + 5) {
bit.clear(); bit.resize(N);
}
void update (int idx, int delta) {
for (; idx < N; idx += idx & (- idx)) {
bit[idx] += delta;
}
}
int query (int idx) {
int res = 0;
for (; idx > 0; idx -= idx & (- idx)) {
res += bit[idx];
}
return res;
}
int range_sum (int lo, int hi) {
return query (hi) - query (lo -1);
}
};
int main () {
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
vector<i64> comp;
for (int i = 0; i < n; i++) {
cin >> a[i];
comp.emplace_back(a[i]);
}
sort (comp.begin(), comp.end());
comp.erase(unique(comp.begin(), comp.end()), comp.end());
FenwickTree menor (n), maior (n);
for (int i = 0; i < n; i++) {
a[i] = (lower_bound (comp.begin(), comp.end(), a[i]) - comp.begin() + 1);
maior.update(a[i], +1);
}
i64 res = 0;
for (int i = 0; i < n; i++) {
maior.update(a[i], -1);
res += 1LL * menor.range_sum (0, a[i] - 1) * maior.range_sum (0, a[i] - 1);
menor.update(a[i], +1);
}
cout << res << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
118 ms |
7396 KB |
Output is correct |
3 |
Correct |
125 ms |
7548 KB |
Output is correct |
4 |
Correct |
115 ms |
7400 KB |
Output is correct |
5 |
Correct |
116 ms |
7396 KB |
Output is correct |
6 |
Correct |
118 ms |
7396 KB |
Output is correct |
7 |
Correct |
117 ms |
7396 KB |
Output is correct |
8 |
Correct |
117 ms |
7396 KB |
Output is correct |
9 |
Correct |
114 ms |
7396 KB |
Output is correct |
10 |
Correct |
113 ms |
7396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
67 ms |
7400 KB |
Output is correct |
2 |
Correct |
72 ms |
7400 KB |
Output is correct |
3 |
Correct |
69 ms |
7408 KB |
Output is correct |
4 |
Correct |
69 ms |
7400 KB |
Output is correct |
5 |
Correct |
69 ms |
7400 KB |
Output is correct |
6 |
Correct |
68 ms |
7400 KB |
Output is correct |
7 |
Correct |
68 ms |
7408 KB |
Output is correct |
8 |
Correct |
72 ms |
7412 KB |
Output is correct |
9 |
Correct |
66 ms |
7400 KB |
Output is correct |
10 |
Correct |
4 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
67 ms |
7400 KB |
Output is correct |
2 |
Correct |
72 ms |
7400 KB |
Output is correct |
3 |
Correct |
69 ms |
7408 KB |
Output is correct |
4 |
Correct |
69 ms |
7400 KB |
Output is correct |
5 |
Correct |
69 ms |
7400 KB |
Output is correct |
6 |
Correct |
68 ms |
7400 KB |
Output is correct |
7 |
Correct |
68 ms |
7408 KB |
Output is correct |
8 |
Correct |
72 ms |
7412 KB |
Output is correct |
9 |
Correct |
66 ms |
7400 KB |
Output is correct |
10 |
Correct |
4 ms |
384 KB |
Output is correct |
11 |
Correct |
82 ms |
7396 KB |
Output is correct |
12 |
Correct |
83 ms |
7396 KB |
Output is correct |
13 |
Correct |
82 ms |
7392 KB |
Output is correct |
14 |
Correct |
84 ms |
7428 KB |
Output is correct |
15 |
Correct |
84 ms |
7396 KB |
Output is correct |
16 |
Correct |
83 ms |
7396 KB |
Output is correct |
17 |
Correct |
80 ms |
7396 KB |
Output is correct |
18 |
Correct |
59 ms |
7400 KB |
Output is correct |
19 |
Correct |
66 ms |
7408 KB |
Output is correct |
20 |
Correct |
4 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
288 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
288 KB |
Output is correct |
11 |
Correct |
9 ms |
640 KB |
Output is correct |
12 |
Correct |
9 ms |
640 KB |
Output is correct |
13 |
Correct |
9 ms |
640 KB |
Output is correct |
14 |
Correct |
10 ms |
640 KB |
Output is correct |
15 |
Correct |
9 ms |
640 KB |
Output is correct |
16 |
Correct |
9 ms |
640 KB |
Output is correct |
17 |
Correct |
9 ms |
640 KB |
Output is correct |
18 |
Correct |
9 ms |
640 KB |
Output is correct |
19 |
Correct |
7 ms |
640 KB |
Output is correct |
20 |
Correct |
4 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
67 ms |
7400 KB |
Output is correct |
2 |
Correct |
72 ms |
7400 KB |
Output is correct |
3 |
Correct |
69 ms |
7408 KB |
Output is correct |
4 |
Correct |
69 ms |
7400 KB |
Output is correct |
5 |
Correct |
69 ms |
7400 KB |
Output is correct |
6 |
Correct |
68 ms |
7400 KB |
Output is correct |
7 |
Correct |
68 ms |
7408 KB |
Output is correct |
8 |
Correct |
72 ms |
7412 KB |
Output is correct |
9 |
Correct |
66 ms |
7400 KB |
Output is correct |
10 |
Correct |
4 ms |
384 KB |
Output is correct |
11 |
Correct |
82 ms |
7396 KB |
Output is correct |
12 |
Correct |
83 ms |
7396 KB |
Output is correct |
13 |
Correct |
82 ms |
7392 KB |
Output is correct |
14 |
Correct |
84 ms |
7428 KB |
Output is correct |
15 |
Correct |
84 ms |
7396 KB |
Output is correct |
16 |
Correct |
83 ms |
7396 KB |
Output is correct |
17 |
Correct |
80 ms |
7396 KB |
Output is correct |
18 |
Correct |
59 ms |
7400 KB |
Output is correct |
19 |
Correct |
66 ms |
7408 KB |
Output is correct |
20 |
Correct |
4 ms |
384 KB |
Output is correct |
21 |
Correct |
140 ms |
7432 KB |
Output is correct |
22 |
Correct |
137 ms |
7396 KB |
Output is correct |
23 |
Correct |
135 ms |
7396 KB |
Output is correct |
24 |
Correct |
140 ms |
7404 KB |
Output is correct |
25 |
Correct |
138 ms |
7392 KB |
Output is correct |
26 |
Correct |
138 ms |
7392 KB |
Output is correct |
27 |
Correct |
139 ms |
7392 KB |
Output is correct |
28 |
Correct |
83 ms |
7396 KB |
Output is correct |
29 |
Correct |
89 ms |
7532 KB |
Output is correct |
30 |
Correct |
4 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
118 ms |
7396 KB |
Output is correct |
3 |
Correct |
125 ms |
7548 KB |
Output is correct |
4 |
Correct |
115 ms |
7400 KB |
Output is correct |
5 |
Correct |
116 ms |
7396 KB |
Output is correct |
6 |
Correct |
118 ms |
7396 KB |
Output is correct |
7 |
Correct |
117 ms |
7396 KB |
Output is correct |
8 |
Correct |
117 ms |
7396 KB |
Output is correct |
9 |
Correct |
114 ms |
7396 KB |
Output is correct |
10 |
Correct |
113 ms |
7396 KB |
Output is correct |
11 |
Correct |
67 ms |
7400 KB |
Output is correct |
12 |
Correct |
72 ms |
7400 KB |
Output is correct |
13 |
Correct |
69 ms |
7408 KB |
Output is correct |
14 |
Correct |
69 ms |
7400 KB |
Output is correct |
15 |
Correct |
69 ms |
7400 KB |
Output is correct |
16 |
Correct |
68 ms |
7400 KB |
Output is correct |
17 |
Correct |
68 ms |
7408 KB |
Output is correct |
18 |
Correct |
72 ms |
7412 KB |
Output is correct |
19 |
Correct |
66 ms |
7400 KB |
Output is correct |
20 |
Correct |
4 ms |
384 KB |
Output is correct |
21 |
Correct |
82 ms |
7396 KB |
Output is correct |
22 |
Correct |
83 ms |
7396 KB |
Output is correct |
23 |
Correct |
82 ms |
7392 KB |
Output is correct |
24 |
Correct |
84 ms |
7428 KB |
Output is correct |
25 |
Correct |
84 ms |
7396 KB |
Output is correct |
26 |
Correct |
83 ms |
7396 KB |
Output is correct |
27 |
Correct |
80 ms |
7396 KB |
Output is correct |
28 |
Correct |
59 ms |
7400 KB |
Output is correct |
29 |
Correct |
66 ms |
7408 KB |
Output is correct |
30 |
Correct |
4 ms |
384 KB |
Output is correct |
31 |
Correct |
5 ms |
384 KB |
Output is correct |
32 |
Correct |
5 ms |
384 KB |
Output is correct |
33 |
Correct |
5 ms |
384 KB |
Output is correct |
34 |
Correct |
5 ms |
384 KB |
Output is correct |
35 |
Correct |
5 ms |
384 KB |
Output is correct |
36 |
Correct |
5 ms |
384 KB |
Output is correct |
37 |
Correct |
5 ms |
384 KB |
Output is correct |
38 |
Correct |
5 ms |
384 KB |
Output is correct |
39 |
Correct |
5 ms |
384 KB |
Output is correct |
40 |
Correct |
5 ms |
288 KB |
Output is correct |
41 |
Correct |
9 ms |
640 KB |
Output is correct |
42 |
Correct |
9 ms |
640 KB |
Output is correct |
43 |
Correct |
9 ms |
640 KB |
Output is correct |
44 |
Correct |
10 ms |
640 KB |
Output is correct |
45 |
Correct |
9 ms |
640 KB |
Output is correct |
46 |
Correct |
9 ms |
640 KB |
Output is correct |
47 |
Correct |
9 ms |
640 KB |
Output is correct |
48 |
Correct |
9 ms |
640 KB |
Output is correct |
49 |
Correct |
7 ms |
640 KB |
Output is correct |
50 |
Correct |
4 ms |
384 KB |
Output is correct |
51 |
Correct |
140 ms |
7432 KB |
Output is correct |
52 |
Correct |
137 ms |
7396 KB |
Output is correct |
53 |
Correct |
135 ms |
7396 KB |
Output is correct |
54 |
Correct |
140 ms |
7404 KB |
Output is correct |
55 |
Correct |
138 ms |
7392 KB |
Output is correct |
56 |
Correct |
138 ms |
7392 KB |
Output is correct |
57 |
Correct |
139 ms |
7392 KB |
Output is correct |
58 |
Correct |
83 ms |
7396 KB |
Output is correct |
59 |
Correct |
89 ms |
7532 KB |
Output is correct |
60 |
Correct |
4 ms |
384 KB |
Output is correct |
61 |
Correct |
183 ms |
7392 KB |
Output is correct |
62 |
Correct |
181 ms |
7388 KB |
Output is correct |
63 |
Correct |
184 ms |
7460 KB |
Output is correct |
64 |
Correct |
178 ms |
7392 KB |
Output is correct |
65 |
Correct |
213 ms |
7396 KB |
Output is correct |
66 |
Correct |
179 ms |
7392 KB |
Output is correct |
67 |
Correct |
181 ms |
7392 KB |
Output is correct |
68 |
Correct |
177 ms |
7392 KB |
Output is correct |
69 |
Correct |
140 ms |
7392 KB |
Output is correct |
70 |
Correct |
5 ms |
384 KB |
Output is correct |