#include <bits/stdc++.h>
using namespace std;
const int N= 3e5 + 2;
int n, aib[N], st[N], dr[N];
long long a[N], b[N];
void norm () {
for (int i = 1; i <= n; i++)
b[i] = a[i];
sort(b + 1, b + n + 1);
for (int i = 1; i <= n; i++)
a[i] = lower_bound(b + 1, b + n + 1, a[i]) - b;
}
int query (int x) {
int s = 0;
for (int i = x; i; i -= (i & -i))
s += aib[i];
return s;
}
void update (int x) {
for (int i = x; i <= n; i += (i & -i))
aib[i] += 1;
}
int main ()
{
cin >> n;
for (int i = 1; i <= n; i++)
cin >> a[i];
norm();
for (int i = 1; i <= n; i++) {
st[i] = query(a[i] - 1);
update(a[i]);
}
long long ans = 0;
memset(aib, 0, sizeof(aib));
for (int i = n; i >= 1; i--) {
dr[i] = query(a[i] -1);
update(a[i]);
ans += 1ll * st[i] * dr[i];
}
cout << ans;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1516 KB |
Output is correct |
2 |
Correct |
252 ms |
14060 KB |
Output is correct |
3 |
Correct |
252 ms |
14152 KB |
Output is correct |
4 |
Correct |
300 ms |
14060 KB |
Output is correct |
5 |
Correct |
255 ms |
14060 KB |
Output is correct |
6 |
Correct |
253 ms |
14060 KB |
Output is correct |
7 |
Correct |
253 ms |
14188 KB |
Output is correct |
8 |
Correct |
250 ms |
14060 KB |
Output is correct |
9 |
Correct |
250 ms |
14060 KB |
Output is correct |
10 |
Correct |
250 ms |
14060 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
108 ms |
8584 KB |
Output is correct |
2 |
Correct |
92 ms |
8532 KB |
Output is correct |
3 |
Correct |
93 ms |
8556 KB |
Output is correct |
4 |
Correct |
94 ms |
8660 KB |
Output is correct |
5 |
Correct |
98 ms |
8532 KB |
Output is correct |
6 |
Correct |
100 ms |
8556 KB |
Output is correct |
7 |
Correct |
92 ms |
8684 KB |
Output is correct |
8 |
Correct |
87 ms |
8556 KB |
Output is correct |
9 |
Correct |
90 ms |
8556 KB |
Output is correct |
10 |
Correct |
1 ms |
1516 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
108 ms |
8584 KB |
Output is correct |
2 |
Correct |
92 ms |
8532 KB |
Output is correct |
3 |
Correct |
93 ms |
8556 KB |
Output is correct |
4 |
Correct |
94 ms |
8660 KB |
Output is correct |
5 |
Correct |
98 ms |
8532 KB |
Output is correct |
6 |
Correct |
100 ms |
8556 KB |
Output is correct |
7 |
Correct |
92 ms |
8684 KB |
Output is correct |
8 |
Correct |
87 ms |
8556 KB |
Output is correct |
9 |
Correct |
90 ms |
8556 KB |
Output is correct |
10 |
Correct |
1 ms |
1516 KB |
Output is correct |
11 |
Correct |
128 ms |
8556 KB |
Output is correct |
12 |
Correct |
128 ms |
8556 KB |
Output is correct |
13 |
Correct |
135 ms |
8556 KB |
Output is correct |
14 |
Correct |
130 ms |
8684 KB |
Output is correct |
15 |
Correct |
128 ms |
8556 KB |
Output is correct |
16 |
Correct |
128 ms |
8556 KB |
Output is correct |
17 |
Correct |
130 ms |
8556 KB |
Output is correct |
18 |
Correct |
88 ms |
8556 KB |
Output is correct |
19 |
Correct |
88 ms |
8556 KB |
Output is correct |
20 |
Correct |
1 ms |
1516 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
1516 KB |
Output is correct |
2 |
Correct |
2 ms |
1516 KB |
Output is correct |
3 |
Correct |
2 ms |
1516 KB |
Output is correct |
4 |
Correct |
2 ms |
1516 KB |
Output is correct |
5 |
Correct |
2 ms |
1516 KB |
Output is correct |
6 |
Correct |
2 ms |
1516 KB |
Output is correct |
7 |
Correct |
2 ms |
1516 KB |
Output is correct |
8 |
Correct |
2 ms |
1516 KB |
Output is correct |
9 |
Correct |
1 ms |
1516 KB |
Output is correct |
10 |
Correct |
1 ms |
1516 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
1516 KB |
Output is correct |
2 |
Correct |
2 ms |
1516 KB |
Output is correct |
3 |
Correct |
2 ms |
1516 KB |
Output is correct |
4 |
Correct |
2 ms |
1516 KB |
Output is correct |
5 |
Correct |
2 ms |
1516 KB |
Output is correct |
6 |
Correct |
2 ms |
1516 KB |
Output is correct |
7 |
Correct |
2 ms |
1516 KB |
Output is correct |
8 |
Correct |
2 ms |
1516 KB |
Output is correct |
9 |
Correct |
1 ms |
1516 KB |
Output is correct |
10 |
Correct |
1 ms |
1516 KB |
Output is correct |
11 |
Correct |
10 ms |
1900 KB |
Output is correct |
12 |
Correct |
10 ms |
1900 KB |
Output is correct |
13 |
Correct |
10 ms |
1900 KB |
Output is correct |
14 |
Correct |
10 ms |
1900 KB |
Output is correct |
15 |
Correct |
12 ms |
1900 KB |
Output is correct |
16 |
Correct |
10 ms |
1900 KB |
Output is correct |
17 |
Correct |
11 ms |
1900 KB |
Output is correct |
18 |
Correct |
11 ms |
1900 KB |
Output is correct |
19 |
Correct |
5 ms |
1772 KB |
Output is correct |
20 |
Correct |
1 ms |
1516 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
108 ms |
8584 KB |
Output is correct |
2 |
Correct |
92 ms |
8532 KB |
Output is correct |
3 |
Correct |
93 ms |
8556 KB |
Output is correct |
4 |
Correct |
94 ms |
8660 KB |
Output is correct |
5 |
Correct |
98 ms |
8532 KB |
Output is correct |
6 |
Correct |
100 ms |
8556 KB |
Output is correct |
7 |
Correct |
92 ms |
8684 KB |
Output is correct |
8 |
Correct |
87 ms |
8556 KB |
Output is correct |
9 |
Correct |
90 ms |
8556 KB |
Output is correct |
10 |
Correct |
1 ms |
1516 KB |
Output is correct |
11 |
Correct |
128 ms |
8556 KB |
Output is correct |
12 |
Correct |
128 ms |
8556 KB |
Output is correct |
13 |
Correct |
135 ms |
8556 KB |
Output is correct |
14 |
Correct |
130 ms |
8684 KB |
Output is correct |
15 |
Correct |
128 ms |
8556 KB |
Output is correct |
16 |
Correct |
128 ms |
8556 KB |
Output is correct |
17 |
Correct |
130 ms |
8556 KB |
Output is correct |
18 |
Correct |
88 ms |
8556 KB |
Output is correct |
19 |
Correct |
88 ms |
8556 KB |
Output is correct |
20 |
Correct |
1 ms |
1516 KB |
Output is correct |
21 |
Correct |
191 ms |
8556 KB |
Output is correct |
22 |
Correct |
194 ms |
8584 KB |
Output is correct |
23 |
Correct |
190 ms |
8556 KB |
Output is correct |
24 |
Correct |
193 ms |
8532 KB |
Output is correct |
25 |
Correct |
197 ms |
8684 KB |
Output is correct |
26 |
Correct |
192 ms |
8556 KB |
Output is correct |
27 |
Correct |
192 ms |
8556 KB |
Output is correct |
28 |
Correct |
131 ms |
8724 KB |
Output is correct |
29 |
Correct |
129 ms |
8556 KB |
Output is correct |
30 |
Correct |
1 ms |
1516 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1516 KB |
Output is correct |
2 |
Correct |
252 ms |
14060 KB |
Output is correct |
3 |
Correct |
252 ms |
14152 KB |
Output is correct |
4 |
Correct |
300 ms |
14060 KB |
Output is correct |
5 |
Correct |
255 ms |
14060 KB |
Output is correct |
6 |
Correct |
253 ms |
14060 KB |
Output is correct |
7 |
Correct |
253 ms |
14188 KB |
Output is correct |
8 |
Correct |
250 ms |
14060 KB |
Output is correct |
9 |
Correct |
250 ms |
14060 KB |
Output is correct |
10 |
Correct |
250 ms |
14060 KB |
Output is correct |
11 |
Correct |
108 ms |
8584 KB |
Output is correct |
12 |
Correct |
92 ms |
8532 KB |
Output is correct |
13 |
Correct |
93 ms |
8556 KB |
Output is correct |
14 |
Correct |
94 ms |
8660 KB |
Output is correct |
15 |
Correct |
98 ms |
8532 KB |
Output is correct |
16 |
Correct |
100 ms |
8556 KB |
Output is correct |
17 |
Correct |
92 ms |
8684 KB |
Output is correct |
18 |
Correct |
87 ms |
8556 KB |
Output is correct |
19 |
Correct |
90 ms |
8556 KB |
Output is correct |
20 |
Correct |
1 ms |
1516 KB |
Output is correct |
21 |
Correct |
128 ms |
8556 KB |
Output is correct |
22 |
Correct |
128 ms |
8556 KB |
Output is correct |
23 |
Correct |
135 ms |
8556 KB |
Output is correct |
24 |
Correct |
130 ms |
8684 KB |
Output is correct |
25 |
Correct |
128 ms |
8556 KB |
Output is correct |
26 |
Correct |
128 ms |
8556 KB |
Output is correct |
27 |
Correct |
130 ms |
8556 KB |
Output is correct |
28 |
Correct |
88 ms |
8556 KB |
Output is correct |
29 |
Correct |
88 ms |
8556 KB |
Output is correct |
30 |
Correct |
1 ms |
1516 KB |
Output is correct |
31 |
Correct |
2 ms |
1516 KB |
Output is correct |
32 |
Correct |
2 ms |
1516 KB |
Output is correct |
33 |
Correct |
2 ms |
1516 KB |
Output is correct |
34 |
Correct |
2 ms |
1516 KB |
Output is correct |
35 |
Correct |
2 ms |
1516 KB |
Output is correct |
36 |
Correct |
2 ms |
1516 KB |
Output is correct |
37 |
Correct |
2 ms |
1516 KB |
Output is correct |
38 |
Correct |
2 ms |
1516 KB |
Output is correct |
39 |
Correct |
1 ms |
1516 KB |
Output is correct |
40 |
Correct |
1 ms |
1516 KB |
Output is correct |
41 |
Correct |
10 ms |
1900 KB |
Output is correct |
42 |
Correct |
10 ms |
1900 KB |
Output is correct |
43 |
Correct |
10 ms |
1900 KB |
Output is correct |
44 |
Correct |
10 ms |
1900 KB |
Output is correct |
45 |
Correct |
12 ms |
1900 KB |
Output is correct |
46 |
Correct |
10 ms |
1900 KB |
Output is correct |
47 |
Correct |
11 ms |
1900 KB |
Output is correct |
48 |
Correct |
11 ms |
1900 KB |
Output is correct |
49 |
Correct |
5 ms |
1772 KB |
Output is correct |
50 |
Correct |
1 ms |
1516 KB |
Output is correct |
51 |
Correct |
191 ms |
8556 KB |
Output is correct |
52 |
Correct |
194 ms |
8584 KB |
Output is correct |
53 |
Correct |
190 ms |
8556 KB |
Output is correct |
54 |
Correct |
193 ms |
8532 KB |
Output is correct |
55 |
Correct |
197 ms |
8684 KB |
Output is correct |
56 |
Correct |
192 ms |
8556 KB |
Output is correct |
57 |
Correct |
192 ms |
8556 KB |
Output is correct |
58 |
Correct |
131 ms |
8724 KB |
Output is correct |
59 |
Correct |
129 ms |
8556 KB |
Output is correct |
60 |
Correct |
1 ms |
1516 KB |
Output is correct |
61 |
Correct |
328 ms |
14060 KB |
Output is correct |
62 |
Correct |
318 ms |
14068 KB |
Output is correct |
63 |
Correct |
317 ms |
14188 KB |
Output is correct |
64 |
Correct |
341 ms |
14064 KB |
Output is correct |
65 |
Correct |
328 ms |
14188 KB |
Output is correct |
66 |
Correct |
321 ms |
14060 KB |
Output is correct |
67 |
Correct |
315 ms |
14060 KB |
Output is correct |
68 |
Correct |
322 ms |
14188 KB |
Output is correct |
69 |
Correct |
196 ms |
10476 KB |
Output is correct |
70 |
Correct |
1 ms |
1516 KB |
Output is correct |