#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const int NMAX = 3e5;
int aib[NMAX + 5];
int n;
void update (int pos, const int &val)
{
for (; pos <= n; pos += pos & -pos)
aib[pos] += val;
}
int query (int pos)
{
int ret = 0;
for (; pos; pos -= pos & -pos)
ret += aib[pos];
return ret;
}
ll a[NMAX + 5];
ll b[NMAX + 5];
ll ans[NMAX + 5];
int main()
{
cin >> n;
for (int i=1; i<=n; i++)
{
cin >> a[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 + 1) + 1;
}
for (int i=1; i<=n; i++)
{
ans[i] = query(a[i] - 1);
update(a[i], +1);
}
memset(aib, 0, sizeof(aib));
for (int i=n; i>0; i--)
{
ans[i] *= query(a[i] - 1);
update(a[i], +1);
}
ll sum = 0;
for (int i=1; i<=n; i++)
sum += ans[i];
cout << sum;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1492 KB |
Output is correct |
2 |
Correct |
189 ms |
14040 KB |
Output is correct |
3 |
Correct |
172 ms |
13948 KB |
Output is correct |
4 |
Correct |
174 ms |
13936 KB |
Output is correct |
5 |
Correct |
206 ms |
14024 KB |
Output is correct |
6 |
Correct |
164 ms |
13960 KB |
Output is correct |
7 |
Correct |
166 ms |
13968 KB |
Output is correct |
8 |
Correct |
162 ms |
13988 KB |
Output is correct |
9 |
Correct |
169 ms |
13960 KB |
Output is correct |
10 |
Correct |
166 ms |
14100 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
67 ms |
9152 KB |
Output is correct |
2 |
Correct |
65 ms |
9084 KB |
Output is correct |
3 |
Correct |
64 ms |
9092 KB |
Output is correct |
4 |
Correct |
66 ms |
9032 KB |
Output is correct |
5 |
Correct |
73 ms |
9020 KB |
Output is correct |
6 |
Correct |
66 ms |
9028 KB |
Output is correct |
7 |
Correct |
67 ms |
9044 KB |
Output is correct |
8 |
Correct |
58 ms |
9088 KB |
Output is correct |
9 |
Correct |
57 ms |
8984 KB |
Output is correct |
10 |
Correct |
1 ms |
1492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
67 ms |
9152 KB |
Output is correct |
2 |
Correct |
65 ms |
9084 KB |
Output is correct |
3 |
Correct |
64 ms |
9092 KB |
Output is correct |
4 |
Correct |
66 ms |
9032 KB |
Output is correct |
5 |
Correct |
73 ms |
9020 KB |
Output is correct |
6 |
Correct |
66 ms |
9028 KB |
Output is correct |
7 |
Correct |
67 ms |
9044 KB |
Output is correct |
8 |
Correct |
58 ms |
9088 KB |
Output is correct |
9 |
Correct |
57 ms |
8984 KB |
Output is correct |
10 |
Correct |
1 ms |
1492 KB |
Output is correct |
11 |
Correct |
97 ms |
9292 KB |
Output is correct |
12 |
Correct |
111 ms |
9348 KB |
Output is correct |
13 |
Correct |
96 ms |
9292 KB |
Output is correct |
14 |
Correct |
101 ms |
9292 KB |
Output is correct |
15 |
Correct |
99 ms |
9292 KB |
Output is correct |
16 |
Correct |
96 ms |
9292 KB |
Output is correct |
17 |
Correct |
97 ms |
9264 KB |
Output is correct |
18 |
Correct |
62 ms |
9280 KB |
Output is correct |
19 |
Correct |
57 ms |
9352 KB |
Output is correct |
20 |
Correct |
1 ms |
1492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1492 KB |
Output is correct |
2 |
Correct |
1 ms |
1468 KB |
Output is correct |
3 |
Correct |
1 ms |
1492 KB |
Output is correct |
4 |
Correct |
1 ms |
1492 KB |
Output is correct |
5 |
Correct |
1 ms |
1492 KB |
Output is correct |
6 |
Correct |
1 ms |
1492 KB |
Output is correct |
7 |
Correct |
2 ms |
1492 KB |
Output is correct |
8 |
Correct |
2 ms |
1492 KB |
Output is correct |
9 |
Correct |
1 ms |
1492 KB |
Output is correct |
10 |
Correct |
1 ms |
1492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1492 KB |
Output is correct |
2 |
Correct |
1 ms |
1468 KB |
Output is correct |
3 |
Correct |
1 ms |
1492 KB |
Output is correct |
4 |
Correct |
1 ms |
1492 KB |
Output is correct |
5 |
Correct |
1 ms |
1492 KB |
Output is correct |
6 |
Correct |
1 ms |
1492 KB |
Output is correct |
7 |
Correct |
2 ms |
1492 KB |
Output is correct |
8 |
Correct |
2 ms |
1492 KB |
Output is correct |
9 |
Correct |
1 ms |
1492 KB |
Output is correct |
10 |
Correct |
1 ms |
1492 KB |
Output is correct |
11 |
Correct |
7 ms |
1876 KB |
Output is correct |
12 |
Correct |
7 ms |
1876 KB |
Output is correct |
13 |
Correct |
7 ms |
1876 KB |
Output is correct |
14 |
Correct |
7 ms |
1876 KB |
Output is correct |
15 |
Correct |
7 ms |
1884 KB |
Output is correct |
16 |
Correct |
7 ms |
1876 KB |
Output is correct |
17 |
Correct |
7 ms |
1876 KB |
Output is correct |
18 |
Correct |
8 ms |
1872 KB |
Output is correct |
19 |
Correct |
5 ms |
1740 KB |
Output is correct |
20 |
Correct |
1 ms |
1492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
67 ms |
9152 KB |
Output is correct |
2 |
Correct |
65 ms |
9084 KB |
Output is correct |
3 |
Correct |
64 ms |
9092 KB |
Output is correct |
4 |
Correct |
66 ms |
9032 KB |
Output is correct |
5 |
Correct |
73 ms |
9020 KB |
Output is correct |
6 |
Correct |
66 ms |
9028 KB |
Output is correct |
7 |
Correct |
67 ms |
9044 KB |
Output is correct |
8 |
Correct |
58 ms |
9088 KB |
Output is correct |
9 |
Correct |
57 ms |
8984 KB |
Output is correct |
10 |
Correct |
1 ms |
1492 KB |
Output is correct |
11 |
Correct |
97 ms |
9292 KB |
Output is correct |
12 |
Correct |
111 ms |
9348 KB |
Output is correct |
13 |
Correct |
96 ms |
9292 KB |
Output is correct |
14 |
Correct |
101 ms |
9292 KB |
Output is correct |
15 |
Correct |
99 ms |
9292 KB |
Output is correct |
16 |
Correct |
96 ms |
9292 KB |
Output is correct |
17 |
Correct |
97 ms |
9264 KB |
Output is correct |
18 |
Correct |
62 ms |
9280 KB |
Output is correct |
19 |
Correct |
57 ms |
9352 KB |
Output is correct |
20 |
Correct |
1 ms |
1492 KB |
Output is correct |
21 |
Correct |
139 ms |
10172 KB |
Output is correct |
22 |
Correct |
147 ms |
10160 KB |
Output is correct |
23 |
Correct |
141 ms |
10120 KB |
Output is correct |
24 |
Correct |
146 ms |
10228 KB |
Output is correct |
25 |
Correct |
140 ms |
10232 KB |
Output is correct |
26 |
Correct |
143 ms |
10176 KB |
Output is correct |
27 |
Correct |
139 ms |
10120 KB |
Output is correct |
28 |
Correct |
87 ms |
10168 KB |
Output is correct |
29 |
Correct |
85 ms |
10156 KB |
Output is correct |
30 |
Correct |
1 ms |
1492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1492 KB |
Output is correct |
2 |
Correct |
189 ms |
14040 KB |
Output is correct |
3 |
Correct |
172 ms |
13948 KB |
Output is correct |
4 |
Correct |
174 ms |
13936 KB |
Output is correct |
5 |
Correct |
206 ms |
14024 KB |
Output is correct |
6 |
Correct |
164 ms |
13960 KB |
Output is correct |
7 |
Correct |
166 ms |
13968 KB |
Output is correct |
8 |
Correct |
162 ms |
13988 KB |
Output is correct |
9 |
Correct |
169 ms |
13960 KB |
Output is correct |
10 |
Correct |
166 ms |
14100 KB |
Output is correct |
11 |
Correct |
67 ms |
9152 KB |
Output is correct |
12 |
Correct |
65 ms |
9084 KB |
Output is correct |
13 |
Correct |
64 ms |
9092 KB |
Output is correct |
14 |
Correct |
66 ms |
9032 KB |
Output is correct |
15 |
Correct |
73 ms |
9020 KB |
Output is correct |
16 |
Correct |
66 ms |
9028 KB |
Output is correct |
17 |
Correct |
67 ms |
9044 KB |
Output is correct |
18 |
Correct |
58 ms |
9088 KB |
Output is correct |
19 |
Correct |
57 ms |
8984 KB |
Output is correct |
20 |
Correct |
1 ms |
1492 KB |
Output is correct |
21 |
Correct |
97 ms |
9292 KB |
Output is correct |
22 |
Correct |
111 ms |
9348 KB |
Output is correct |
23 |
Correct |
96 ms |
9292 KB |
Output is correct |
24 |
Correct |
101 ms |
9292 KB |
Output is correct |
25 |
Correct |
99 ms |
9292 KB |
Output is correct |
26 |
Correct |
96 ms |
9292 KB |
Output is correct |
27 |
Correct |
97 ms |
9264 KB |
Output is correct |
28 |
Correct |
62 ms |
9280 KB |
Output is correct |
29 |
Correct |
57 ms |
9352 KB |
Output is correct |
30 |
Correct |
1 ms |
1492 KB |
Output is correct |
31 |
Correct |
1 ms |
1492 KB |
Output is correct |
32 |
Correct |
1 ms |
1468 KB |
Output is correct |
33 |
Correct |
1 ms |
1492 KB |
Output is correct |
34 |
Correct |
1 ms |
1492 KB |
Output is correct |
35 |
Correct |
1 ms |
1492 KB |
Output is correct |
36 |
Correct |
1 ms |
1492 KB |
Output is correct |
37 |
Correct |
2 ms |
1492 KB |
Output is correct |
38 |
Correct |
2 ms |
1492 KB |
Output is correct |
39 |
Correct |
1 ms |
1492 KB |
Output is correct |
40 |
Correct |
1 ms |
1492 KB |
Output is correct |
41 |
Correct |
7 ms |
1876 KB |
Output is correct |
42 |
Correct |
7 ms |
1876 KB |
Output is correct |
43 |
Correct |
7 ms |
1876 KB |
Output is correct |
44 |
Correct |
7 ms |
1876 KB |
Output is correct |
45 |
Correct |
7 ms |
1884 KB |
Output is correct |
46 |
Correct |
7 ms |
1876 KB |
Output is correct |
47 |
Correct |
7 ms |
1876 KB |
Output is correct |
48 |
Correct |
8 ms |
1872 KB |
Output is correct |
49 |
Correct |
5 ms |
1740 KB |
Output is correct |
50 |
Correct |
1 ms |
1492 KB |
Output is correct |
51 |
Correct |
139 ms |
10172 KB |
Output is correct |
52 |
Correct |
147 ms |
10160 KB |
Output is correct |
53 |
Correct |
141 ms |
10120 KB |
Output is correct |
54 |
Correct |
146 ms |
10228 KB |
Output is correct |
55 |
Correct |
140 ms |
10232 KB |
Output is correct |
56 |
Correct |
143 ms |
10176 KB |
Output is correct |
57 |
Correct |
139 ms |
10120 KB |
Output is correct |
58 |
Correct |
87 ms |
10168 KB |
Output is correct |
59 |
Correct |
85 ms |
10156 KB |
Output is correct |
60 |
Correct |
1 ms |
1492 KB |
Output is correct |
61 |
Correct |
223 ms |
14004 KB |
Output is correct |
62 |
Correct |
220 ms |
14008 KB |
Output is correct |
63 |
Correct |
220 ms |
14116 KB |
Output is correct |
64 |
Correct |
228 ms |
14016 KB |
Output is correct |
65 |
Correct |
235 ms |
14008 KB |
Output is correct |
66 |
Correct |
216 ms |
14032 KB |
Output is correct |
67 |
Correct |
219 ms |
14028 KB |
Output is correct |
68 |
Correct |
219 ms |
13968 KB |
Output is correct |
69 |
Correct |
164 ms |
10272 KB |
Output is correct |
70 |
Correct |
1 ms |
1492 KB |
Output is correct |