#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 |
1 |
Correct |
5 ms |
2432 KB |
Output is correct |
2 |
Correct |
36 ms |
5888 KB |
Output is correct |
3 |
Correct |
37 ms |
6016 KB |
Output is correct |
4 |
Correct |
36 ms |
5880 KB |
Output is correct |
5 |
Correct |
36 ms |
6016 KB |
Output is correct |
6 |
Correct |
36 ms |
6016 KB |
Output is correct |
7 |
Correct |
36 ms |
5888 KB |
Output is correct |
8 |
Correct |
36 ms |
6016 KB |
Output is correct |
9 |
Correct |
36 ms |
5888 KB |
Output is correct |
10 |
Correct |
36 ms |
5888 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
60 ms |
6552 KB |
Output is correct |
2 |
Correct |
54 ms |
6520 KB |
Output is correct |
3 |
Correct |
56 ms |
6520 KB |
Output is correct |
4 |
Correct |
58 ms |
6520 KB |
Output is correct |
5 |
Correct |
55 ms |
6520 KB |
Output is correct |
6 |
Correct |
58 ms |
6520 KB |
Output is correct |
7 |
Correct |
55 ms |
6520 KB |
Output is correct |
8 |
Correct |
52 ms |
6520 KB |
Output is correct |
9 |
Correct |
52 ms |
6520 KB |
Output is correct |
10 |
Correct |
6 ms |
2432 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
60 ms |
6552 KB |
Output is correct |
2 |
Correct |
54 ms |
6520 KB |
Output is correct |
3 |
Correct |
56 ms |
6520 KB |
Output is correct |
4 |
Correct |
58 ms |
6520 KB |
Output is correct |
5 |
Correct |
55 ms |
6520 KB |
Output is correct |
6 |
Correct |
58 ms |
6520 KB |
Output is correct |
7 |
Correct |
55 ms |
6520 KB |
Output is correct |
8 |
Correct |
52 ms |
6520 KB |
Output is correct |
9 |
Correct |
52 ms |
6520 KB |
Output is correct |
10 |
Correct |
6 ms |
2432 KB |
Output is correct |
11 |
Correct |
78 ms |
6776 KB |
Output is correct |
12 |
Correct |
81 ms |
6776 KB |
Output is correct |
13 |
Correct |
78 ms |
6796 KB |
Output is correct |
14 |
Correct |
77 ms |
6776 KB |
Output is correct |
15 |
Correct |
80 ms |
6776 KB |
Output is correct |
16 |
Correct |
76 ms |
6776 KB |
Output is correct |
17 |
Correct |
80 ms |
6776 KB |
Output is correct |
18 |
Correct |
53 ms |
6780 KB |
Output is correct |
19 |
Correct |
53 ms |
6752 KB |
Output is correct |
20 |
Correct |
6 ms |
2432 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
2432 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
2432 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
60 ms |
6552 KB |
Output is correct |
2 |
Correct |
54 ms |
6520 KB |
Output is correct |
3 |
Correct |
56 ms |
6520 KB |
Output is correct |
4 |
Correct |
58 ms |
6520 KB |
Output is correct |
5 |
Correct |
55 ms |
6520 KB |
Output is correct |
6 |
Correct |
58 ms |
6520 KB |
Output is correct |
7 |
Correct |
55 ms |
6520 KB |
Output is correct |
8 |
Correct |
52 ms |
6520 KB |
Output is correct |
9 |
Correct |
52 ms |
6520 KB |
Output is correct |
10 |
Correct |
6 ms |
2432 KB |
Output is correct |
11 |
Correct |
78 ms |
6776 KB |
Output is correct |
12 |
Correct |
81 ms |
6776 KB |
Output is correct |
13 |
Correct |
78 ms |
6796 KB |
Output is correct |
14 |
Correct |
77 ms |
6776 KB |
Output is correct |
15 |
Correct |
80 ms |
6776 KB |
Output is correct |
16 |
Correct |
76 ms |
6776 KB |
Output is correct |
17 |
Correct |
80 ms |
6776 KB |
Output is correct |
18 |
Correct |
53 ms |
6780 KB |
Output is correct |
19 |
Correct |
53 ms |
6752 KB |
Output is correct |
20 |
Correct |
6 ms |
2432 KB |
Output is correct |
21 |
Correct |
223 ms |
12188 KB |
Output is correct |
22 |
Correct |
239 ms |
12300 KB |
Output is correct |
23 |
Correct |
216 ms |
12156 KB |
Output is correct |
24 |
Correct |
222 ms |
12152 KB |
Output is correct |
25 |
Correct |
238 ms |
12152 KB |
Output is correct |
26 |
Correct |
223 ms |
12168 KB |
Output is correct |
27 |
Correct |
216 ms |
12128 KB |
Output is correct |
28 |
Correct |
126 ms |
12280 KB |
Output is correct |
29 |
Correct |
125 ms |
12152 KB |
Output is correct |
30 |
Correct |
5 ms |
2432 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
2432 KB |
Output is correct |
2 |
Correct |
36 ms |
5888 KB |
Output is correct |
3 |
Correct |
37 ms |
6016 KB |
Output is correct |
4 |
Correct |
36 ms |
5880 KB |
Output is correct |
5 |
Correct |
36 ms |
6016 KB |
Output is correct |
6 |
Correct |
36 ms |
6016 KB |
Output is correct |
7 |
Correct |
36 ms |
5888 KB |
Output is correct |
8 |
Correct |
36 ms |
6016 KB |
Output is correct |
9 |
Correct |
36 ms |
5888 KB |
Output is correct |
10 |
Correct |
36 ms |
5888 KB |
Output is correct |
11 |
Correct |
60 ms |
6552 KB |
Output is correct |
12 |
Correct |
54 ms |
6520 KB |
Output is correct |
13 |
Correct |
56 ms |
6520 KB |
Output is correct |
14 |
Correct |
58 ms |
6520 KB |
Output is correct |
15 |
Correct |
55 ms |
6520 KB |
Output is correct |
16 |
Correct |
58 ms |
6520 KB |
Output is correct |
17 |
Correct |
55 ms |
6520 KB |
Output is correct |
18 |
Correct |
52 ms |
6520 KB |
Output is correct |
19 |
Correct |
52 ms |
6520 KB |
Output is correct |
20 |
Correct |
6 ms |
2432 KB |
Output is correct |
21 |
Correct |
78 ms |
6776 KB |
Output is correct |
22 |
Correct |
81 ms |
6776 KB |
Output is correct |
23 |
Correct |
78 ms |
6796 KB |
Output is correct |
24 |
Correct |
77 ms |
6776 KB |
Output is correct |
25 |
Correct |
80 ms |
6776 KB |
Output is correct |
26 |
Correct |
76 ms |
6776 KB |
Output is correct |
27 |
Correct |
80 ms |
6776 KB |
Output is correct |
28 |
Correct |
53 ms |
6780 KB |
Output is correct |
29 |
Correct |
53 ms |
6752 KB |
Output is correct |
30 |
Correct |
6 ms |
2432 KB |
Output is correct |
31 |
Incorrect |
5 ms |
2432 KB |
Output isn't correct |
32 |
Halted |
0 ms |
0 KB |
- |