#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<ll> V(N);
map<ll, int> M;
for (ll& i : V) {
cin >> i;
M[i] = 0;
}
int x = 0;
for (auto& [k, v] : M) {
v = x++;
}
for (ll& 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;
}
Compilation message
Mountains.cpp: In function 'int main()':
Mountains.cpp:38:19: warning: unused variable 'k' [-Wunused-variable]
for (auto& [k, v] : M) {
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
2432 KB |
Output is correct |
2 |
Correct |
239 ms |
31352 KB |
Output is correct |
3 |
Correct |
231 ms |
31480 KB |
Output is correct |
4 |
Correct |
234 ms |
31352 KB |
Output is correct |
5 |
Correct |
234 ms |
31424 KB |
Output is correct |
6 |
Correct |
226 ms |
31608 KB |
Output is correct |
7 |
Correct |
243 ms |
31480 KB |
Output is correct |
8 |
Correct |
240 ms |
31480 KB |
Output is correct |
9 |
Correct |
207 ms |
22584 KB |
Output is correct |
10 |
Correct |
190 ms |
22392 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
55 ms |
7160 KB |
Output is correct |
2 |
Correct |
53 ms |
7032 KB |
Output is correct |
3 |
Correct |
58 ms |
7160 KB |
Output is correct |
4 |
Correct |
54 ms |
7032 KB |
Output is correct |
5 |
Correct |
54 ms |
7032 KB |
Output is correct |
6 |
Correct |
58 ms |
7032 KB |
Output is correct |
7 |
Correct |
58 ms |
7032 KB |
Output is correct |
8 |
Correct |
52 ms |
7160 KB |
Output is correct |
9 |
Correct |
54 ms |
7160 KB |
Output is correct |
10 |
Correct |
6 ms |
2432 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
55 ms |
7160 KB |
Output is correct |
2 |
Correct |
53 ms |
7032 KB |
Output is correct |
3 |
Correct |
58 ms |
7160 KB |
Output is correct |
4 |
Correct |
54 ms |
7032 KB |
Output is correct |
5 |
Correct |
54 ms |
7032 KB |
Output is correct |
6 |
Correct |
58 ms |
7032 KB |
Output is correct |
7 |
Correct |
58 ms |
7032 KB |
Output is correct |
8 |
Correct |
52 ms |
7160 KB |
Output is correct |
9 |
Correct |
54 ms |
7160 KB |
Output is correct |
10 |
Correct |
6 ms |
2432 KB |
Output is correct |
11 |
Correct |
76 ms |
7160 KB |
Output is correct |
12 |
Correct |
77 ms |
7032 KB |
Output is correct |
13 |
Correct |
80 ms |
7112 KB |
Output is correct |
14 |
Correct |
84 ms |
7160 KB |
Output is correct |
15 |
Correct |
77 ms |
7032 KB |
Output is correct |
16 |
Correct |
77 ms |
7032 KB |
Output is correct |
17 |
Correct |
78 ms |
7032 KB |
Output is correct |
18 |
Correct |
55 ms |
7160 KB |
Output is correct |
19 |
Correct |
54 ms |
7032 KB |
Output is correct |
20 |
Correct |
6 ms |
2432 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
2432 KB |
Output is correct |
2 |
Correct |
6 ms |
2432 KB |
Output is correct |
3 |
Correct |
6 ms |
2432 KB |
Output is correct |
4 |
Correct |
6 ms |
2432 KB |
Output is correct |
5 |
Correct |
6 ms |
2432 KB |
Output is correct |
6 |
Correct |
6 ms |
2432 KB |
Output is correct |
7 |
Correct |
6 ms |
2432 KB |
Output is correct |
8 |
Correct |
6 ms |
2432 KB |
Output is correct |
9 |
Correct |
6 ms |
2432 KB |
Output is correct |
10 |
Correct |
6 ms |
2432 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
2432 KB |
Output is correct |
2 |
Correct |
6 ms |
2432 KB |
Output is correct |
3 |
Correct |
6 ms |
2432 KB |
Output is correct |
4 |
Correct |
6 ms |
2432 KB |
Output is correct |
5 |
Correct |
6 ms |
2432 KB |
Output is correct |
6 |
Correct |
6 ms |
2432 KB |
Output is correct |
7 |
Correct |
6 ms |
2432 KB |
Output is correct |
8 |
Correct |
6 ms |
2432 KB |
Output is correct |
9 |
Correct |
6 ms |
2432 KB |
Output is correct |
10 |
Correct |
6 ms |
2432 KB |
Output is correct |
11 |
Correct |
13 ms |
3328 KB |
Output is correct |
12 |
Correct |
13 ms |
3328 KB |
Output is correct |
13 |
Correct |
13 ms |
3328 KB |
Output is correct |
14 |
Correct |
13 ms |
3328 KB |
Output is correct |
15 |
Correct |
13 ms |
3328 KB |
Output is correct |
16 |
Correct |
13 ms |
3328 KB |
Output is correct |
17 |
Correct |
13 ms |
3328 KB |
Output is correct |
18 |
Correct |
11 ms |
2944 KB |
Output is correct |
19 |
Correct |
9 ms |
2560 KB |
Output is correct |
20 |
Correct |
6 ms |
2432 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
55 ms |
7160 KB |
Output is correct |
2 |
Correct |
53 ms |
7032 KB |
Output is correct |
3 |
Correct |
58 ms |
7160 KB |
Output is correct |
4 |
Correct |
54 ms |
7032 KB |
Output is correct |
5 |
Correct |
54 ms |
7032 KB |
Output is correct |
6 |
Correct |
58 ms |
7032 KB |
Output is correct |
7 |
Correct |
58 ms |
7032 KB |
Output is correct |
8 |
Correct |
52 ms |
7160 KB |
Output is correct |
9 |
Correct |
54 ms |
7160 KB |
Output is correct |
10 |
Correct |
6 ms |
2432 KB |
Output is correct |
11 |
Correct |
76 ms |
7160 KB |
Output is correct |
12 |
Correct |
77 ms |
7032 KB |
Output is correct |
13 |
Correct |
80 ms |
7112 KB |
Output is correct |
14 |
Correct |
84 ms |
7160 KB |
Output is correct |
15 |
Correct |
77 ms |
7032 KB |
Output is correct |
16 |
Correct |
77 ms |
7032 KB |
Output is correct |
17 |
Correct |
78 ms |
7032 KB |
Output is correct |
18 |
Correct |
55 ms |
7160 KB |
Output is correct |
19 |
Correct |
54 ms |
7032 KB |
Output is correct |
20 |
Correct |
6 ms |
2432 KB |
Output is correct |
21 |
Correct |
255 ms |
13176 KB |
Output is correct |
22 |
Correct |
244 ms |
13052 KB |
Output is correct |
23 |
Correct |
233 ms |
13048 KB |
Output is correct |
24 |
Correct |
253 ms |
13356 KB |
Output is correct |
25 |
Correct |
236 ms |
13048 KB |
Output is correct |
26 |
Correct |
235 ms |
13048 KB |
Output is correct |
27 |
Correct |
239 ms |
13304 KB |
Output is correct |
28 |
Correct |
132 ms |
13048 KB |
Output is correct |
29 |
Correct |
137 ms |
12992 KB |
Output is correct |
30 |
Correct |
6 ms |
2432 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
2432 KB |
Output is correct |
2 |
Correct |
239 ms |
31352 KB |
Output is correct |
3 |
Correct |
231 ms |
31480 KB |
Output is correct |
4 |
Correct |
234 ms |
31352 KB |
Output is correct |
5 |
Correct |
234 ms |
31424 KB |
Output is correct |
6 |
Correct |
226 ms |
31608 KB |
Output is correct |
7 |
Correct |
243 ms |
31480 KB |
Output is correct |
8 |
Correct |
240 ms |
31480 KB |
Output is correct |
9 |
Correct |
207 ms |
22584 KB |
Output is correct |
10 |
Correct |
190 ms |
22392 KB |
Output is correct |
11 |
Correct |
55 ms |
7160 KB |
Output is correct |
12 |
Correct |
53 ms |
7032 KB |
Output is correct |
13 |
Correct |
58 ms |
7160 KB |
Output is correct |
14 |
Correct |
54 ms |
7032 KB |
Output is correct |
15 |
Correct |
54 ms |
7032 KB |
Output is correct |
16 |
Correct |
58 ms |
7032 KB |
Output is correct |
17 |
Correct |
58 ms |
7032 KB |
Output is correct |
18 |
Correct |
52 ms |
7160 KB |
Output is correct |
19 |
Correct |
54 ms |
7160 KB |
Output is correct |
20 |
Correct |
6 ms |
2432 KB |
Output is correct |
21 |
Correct |
76 ms |
7160 KB |
Output is correct |
22 |
Correct |
77 ms |
7032 KB |
Output is correct |
23 |
Correct |
80 ms |
7112 KB |
Output is correct |
24 |
Correct |
84 ms |
7160 KB |
Output is correct |
25 |
Correct |
77 ms |
7032 KB |
Output is correct |
26 |
Correct |
77 ms |
7032 KB |
Output is correct |
27 |
Correct |
78 ms |
7032 KB |
Output is correct |
28 |
Correct |
55 ms |
7160 KB |
Output is correct |
29 |
Correct |
54 ms |
7032 KB |
Output is correct |
30 |
Correct |
6 ms |
2432 KB |
Output is correct |
31 |
Correct |
6 ms |
2432 KB |
Output is correct |
32 |
Correct |
6 ms |
2432 KB |
Output is correct |
33 |
Correct |
6 ms |
2432 KB |
Output is correct |
34 |
Correct |
6 ms |
2432 KB |
Output is correct |
35 |
Correct |
6 ms |
2432 KB |
Output is correct |
36 |
Correct |
6 ms |
2432 KB |
Output is correct |
37 |
Correct |
6 ms |
2432 KB |
Output is correct |
38 |
Correct |
6 ms |
2432 KB |
Output is correct |
39 |
Correct |
6 ms |
2432 KB |
Output is correct |
40 |
Correct |
6 ms |
2432 KB |
Output is correct |
41 |
Correct |
13 ms |
3328 KB |
Output is correct |
42 |
Correct |
13 ms |
3328 KB |
Output is correct |
43 |
Correct |
13 ms |
3328 KB |
Output is correct |
44 |
Correct |
13 ms |
3328 KB |
Output is correct |
45 |
Correct |
13 ms |
3328 KB |
Output is correct |
46 |
Correct |
13 ms |
3328 KB |
Output is correct |
47 |
Correct |
13 ms |
3328 KB |
Output is correct |
48 |
Correct |
11 ms |
2944 KB |
Output is correct |
49 |
Correct |
9 ms |
2560 KB |
Output is correct |
50 |
Correct |
6 ms |
2432 KB |
Output is correct |
51 |
Correct |
255 ms |
13176 KB |
Output is correct |
52 |
Correct |
244 ms |
13052 KB |
Output is correct |
53 |
Correct |
233 ms |
13048 KB |
Output is correct |
54 |
Correct |
253 ms |
13356 KB |
Output is correct |
55 |
Correct |
236 ms |
13048 KB |
Output is correct |
56 |
Correct |
235 ms |
13048 KB |
Output is correct |
57 |
Correct |
239 ms |
13304 KB |
Output is correct |
58 |
Correct |
132 ms |
13048 KB |
Output is correct |
59 |
Correct |
137 ms |
12992 KB |
Output is correct |
60 |
Correct |
6 ms |
2432 KB |
Output is correct |
61 |
Correct |
474 ms |
31452 KB |
Output is correct |
62 |
Correct |
478 ms |
31456 KB |
Output is correct |
63 |
Correct |
458 ms |
31480 KB |
Output is correct |
64 |
Correct |
493 ms |
31624 KB |
Output is correct |
65 |
Correct |
485 ms |
31480 KB |
Output is correct |
66 |
Correct |
471 ms |
31480 KB |
Output is correct |
67 |
Correct |
487 ms |
31480 KB |
Output is correct |
68 |
Correct |
389 ms |
22392 KB |
Output is correct |
69 |
Correct |
289 ms |
17272 KB |
Output is correct |
70 |
Correct |
6 ms |
2432 KB |
Output is correct |