#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
const int MOD = 998244353;
ll binpow(ll a, ll p, int mod = MOD) {
ll res = 1;
while (p) {
if (p & 1) {
(res *= a) %= mod;
}
p >>= 1;
(a *= a) %= mod;
}
return res;
}
ll gcd(ll a, ll b) {
return b == 0 ? a : gcd(b, a % b);
}
const int N = 3e5 + 5;
int fenw[N];
void add(int pos) {
for (; pos < N; pos |= pos + 1) {
fenw[pos]++;
}
}
ll get(int pos) {
ll res = 0;
for (; pos >= 0; pos = (pos & (pos + 1)) - 1) {
res += fenw[pos];
}
return res;
}
void solve() {
int n;
cin >> n;
vector<ll> h(n);
set<ll> setik;
for (int i = 0; i < n; i++) {
cin >> h[i];
setik.insert(h[i]);
}
int cur = 0;
map<ll, int> id;
for (ll val : setik) {
id[val] = cur++;
}
vector<ll> l(n), r(n);
for (int i = 0; i < n; i++) {
l[i] = get(id[h[i]] - 1);
add(id[h[i]]);
}
fill(fenw, fenw + N, 0);
for (int i = n - 1; i >= 0; i--) {
r[i] = get(id[h[i]] - 1);
add(id[h[i]]);
}
ll ans = 0;
for (int i = 0; i < n; i++) {
ans += l[i] * r[i];
}
cout << ans << endl;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int T = 1;
// cin >> T;
for (int tc = 1; tc <= T; tc++) {
// cout << "Case #" << tc << ": ";
solve();
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
1484 KB |
Output is correct |
2 |
Correct |
390 ms |
46940 KB |
Output is correct |
3 |
Correct |
432 ms |
41468 KB |
Output is correct |
4 |
Correct |
390 ms |
41444 KB |
Output is correct |
5 |
Correct |
389 ms |
41408 KB |
Output is correct |
6 |
Correct |
453 ms |
41396 KB |
Output is correct |
7 |
Correct |
459 ms |
41400 KB |
Output is correct |
8 |
Correct |
457 ms |
41288 KB |
Output is correct |
9 |
Correct |
326 ms |
25544 KB |
Output is correct |
10 |
Correct |
318 ms |
25524 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
54 ms |
9112 KB |
Output is correct |
2 |
Correct |
60 ms |
8524 KB |
Output is correct |
3 |
Correct |
54 ms |
8528 KB |
Output is correct |
4 |
Correct |
55 ms |
8440 KB |
Output is correct |
5 |
Correct |
62 ms |
8528 KB |
Output is correct |
6 |
Correct |
55 ms |
8436 KB |
Output is correct |
7 |
Correct |
62 ms |
8524 KB |
Output is correct |
8 |
Correct |
52 ms |
8524 KB |
Output is correct |
9 |
Correct |
57 ms |
8524 KB |
Output is correct |
10 |
Correct |
1 ms |
1484 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
54 ms |
9112 KB |
Output is correct |
2 |
Correct |
60 ms |
8524 KB |
Output is correct |
3 |
Correct |
54 ms |
8528 KB |
Output is correct |
4 |
Correct |
55 ms |
8440 KB |
Output is correct |
5 |
Correct |
62 ms |
8528 KB |
Output is correct |
6 |
Correct |
55 ms |
8436 KB |
Output is correct |
7 |
Correct |
62 ms |
8524 KB |
Output is correct |
8 |
Correct |
52 ms |
8524 KB |
Output is correct |
9 |
Correct |
57 ms |
8524 KB |
Output is correct |
10 |
Correct |
1 ms |
1484 KB |
Output is correct |
11 |
Correct |
101 ms |
8432 KB |
Output is correct |
12 |
Correct |
92 ms |
8440 KB |
Output is correct |
13 |
Correct |
91 ms |
8452 KB |
Output is correct |
14 |
Correct |
94 ms |
8432 KB |
Output is correct |
15 |
Correct |
90 ms |
8428 KB |
Output is correct |
16 |
Correct |
93 ms |
8516 KB |
Output is correct |
17 |
Correct |
92 ms |
8544 KB |
Output is correct |
18 |
Correct |
82 ms |
8440 KB |
Output is correct |
19 |
Correct |
70 ms |
8556 KB |
Output is correct |
20 |
Correct |
2 ms |
1484 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
1484 KB |
Output is correct |
2 |
Correct |
2 ms |
1484 KB |
Output is correct |
3 |
Correct |
2 ms |
1484 KB |
Output is correct |
4 |
Correct |
2 ms |
1484 KB |
Output is correct |
5 |
Correct |
2 ms |
1484 KB |
Output is correct |
6 |
Correct |
2 ms |
1484 KB |
Output is correct |
7 |
Correct |
2 ms |
1484 KB |
Output is correct |
8 |
Correct |
2 ms |
1484 KB |
Output is correct |
9 |
Correct |
2 ms |
1484 KB |
Output is correct |
10 |
Correct |
2 ms |
1484 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
1484 KB |
Output is correct |
2 |
Correct |
2 ms |
1484 KB |
Output is correct |
3 |
Correct |
2 ms |
1484 KB |
Output is correct |
4 |
Correct |
2 ms |
1484 KB |
Output is correct |
5 |
Correct |
2 ms |
1484 KB |
Output is correct |
6 |
Correct |
2 ms |
1484 KB |
Output is correct |
7 |
Correct |
2 ms |
1484 KB |
Output is correct |
8 |
Correct |
2 ms |
1484 KB |
Output is correct |
9 |
Correct |
2 ms |
1484 KB |
Output is correct |
10 |
Correct |
2 ms |
1484 KB |
Output is correct |
11 |
Correct |
15 ms |
2892 KB |
Output is correct |
12 |
Correct |
15 ms |
2892 KB |
Output is correct |
13 |
Correct |
16 ms |
2892 KB |
Output is correct |
14 |
Correct |
19 ms |
2892 KB |
Output is correct |
15 |
Correct |
16 ms |
2892 KB |
Output is correct |
16 |
Correct |
16 ms |
2920 KB |
Output is correct |
17 |
Correct |
16 ms |
3008 KB |
Output is correct |
18 |
Correct |
13 ms |
2388 KB |
Output is correct |
19 |
Correct |
7 ms |
1740 KB |
Output is correct |
20 |
Correct |
1 ms |
1484 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
54 ms |
9112 KB |
Output is correct |
2 |
Correct |
60 ms |
8524 KB |
Output is correct |
3 |
Correct |
54 ms |
8528 KB |
Output is correct |
4 |
Correct |
55 ms |
8440 KB |
Output is correct |
5 |
Correct |
62 ms |
8528 KB |
Output is correct |
6 |
Correct |
55 ms |
8436 KB |
Output is correct |
7 |
Correct |
62 ms |
8524 KB |
Output is correct |
8 |
Correct |
52 ms |
8524 KB |
Output is correct |
9 |
Correct |
57 ms |
8524 KB |
Output is correct |
10 |
Correct |
1 ms |
1484 KB |
Output is correct |
11 |
Correct |
101 ms |
8432 KB |
Output is correct |
12 |
Correct |
92 ms |
8440 KB |
Output is correct |
13 |
Correct |
91 ms |
8452 KB |
Output is correct |
14 |
Correct |
94 ms |
8432 KB |
Output is correct |
15 |
Correct |
90 ms |
8428 KB |
Output is correct |
16 |
Correct |
93 ms |
8516 KB |
Output is correct |
17 |
Correct |
92 ms |
8544 KB |
Output is correct |
18 |
Correct |
82 ms |
8440 KB |
Output is correct |
19 |
Correct |
70 ms |
8556 KB |
Output is correct |
20 |
Correct |
2 ms |
1484 KB |
Output is correct |
21 |
Correct |
808 ms |
18940 KB |
Output is correct |
22 |
Correct |
654 ms |
18912 KB |
Output is correct |
23 |
Correct |
638 ms |
18940 KB |
Output is correct |
24 |
Correct |
623 ms |
18884 KB |
Output is correct |
25 |
Correct |
766 ms |
19028 KB |
Output is correct |
26 |
Correct |
606 ms |
19056 KB |
Output is correct |
27 |
Correct |
784 ms |
18932 KB |
Output is correct |
28 |
Correct |
226 ms |
18936 KB |
Output is correct |
29 |
Correct |
235 ms |
18936 KB |
Output is correct |
30 |
Correct |
1 ms |
1484 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
1484 KB |
Output is correct |
2 |
Correct |
390 ms |
46940 KB |
Output is correct |
3 |
Correct |
432 ms |
41468 KB |
Output is correct |
4 |
Correct |
390 ms |
41444 KB |
Output is correct |
5 |
Correct |
389 ms |
41408 KB |
Output is correct |
6 |
Correct |
453 ms |
41396 KB |
Output is correct |
7 |
Correct |
459 ms |
41400 KB |
Output is correct |
8 |
Correct |
457 ms |
41288 KB |
Output is correct |
9 |
Correct |
326 ms |
25544 KB |
Output is correct |
10 |
Correct |
318 ms |
25524 KB |
Output is correct |
11 |
Correct |
54 ms |
9112 KB |
Output is correct |
12 |
Correct |
60 ms |
8524 KB |
Output is correct |
13 |
Correct |
54 ms |
8528 KB |
Output is correct |
14 |
Correct |
55 ms |
8440 KB |
Output is correct |
15 |
Correct |
62 ms |
8528 KB |
Output is correct |
16 |
Correct |
55 ms |
8436 KB |
Output is correct |
17 |
Correct |
62 ms |
8524 KB |
Output is correct |
18 |
Correct |
52 ms |
8524 KB |
Output is correct |
19 |
Correct |
57 ms |
8524 KB |
Output is correct |
20 |
Correct |
1 ms |
1484 KB |
Output is correct |
21 |
Correct |
101 ms |
8432 KB |
Output is correct |
22 |
Correct |
92 ms |
8440 KB |
Output is correct |
23 |
Correct |
91 ms |
8452 KB |
Output is correct |
24 |
Correct |
94 ms |
8432 KB |
Output is correct |
25 |
Correct |
90 ms |
8428 KB |
Output is correct |
26 |
Correct |
93 ms |
8516 KB |
Output is correct |
27 |
Correct |
92 ms |
8544 KB |
Output is correct |
28 |
Correct |
82 ms |
8440 KB |
Output is correct |
29 |
Correct |
70 ms |
8556 KB |
Output is correct |
30 |
Correct |
2 ms |
1484 KB |
Output is correct |
31 |
Correct |
2 ms |
1484 KB |
Output is correct |
32 |
Correct |
2 ms |
1484 KB |
Output is correct |
33 |
Correct |
2 ms |
1484 KB |
Output is correct |
34 |
Correct |
2 ms |
1484 KB |
Output is correct |
35 |
Correct |
2 ms |
1484 KB |
Output is correct |
36 |
Correct |
2 ms |
1484 KB |
Output is correct |
37 |
Correct |
2 ms |
1484 KB |
Output is correct |
38 |
Correct |
2 ms |
1484 KB |
Output is correct |
39 |
Correct |
2 ms |
1484 KB |
Output is correct |
40 |
Correct |
2 ms |
1484 KB |
Output is correct |
41 |
Correct |
15 ms |
2892 KB |
Output is correct |
42 |
Correct |
15 ms |
2892 KB |
Output is correct |
43 |
Correct |
16 ms |
2892 KB |
Output is correct |
44 |
Correct |
19 ms |
2892 KB |
Output is correct |
45 |
Correct |
16 ms |
2892 KB |
Output is correct |
46 |
Correct |
16 ms |
2920 KB |
Output is correct |
47 |
Correct |
16 ms |
3008 KB |
Output is correct |
48 |
Correct |
13 ms |
2388 KB |
Output is correct |
49 |
Correct |
7 ms |
1740 KB |
Output is correct |
50 |
Correct |
1 ms |
1484 KB |
Output is correct |
51 |
Correct |
808 ms |
18940 KB |
Output is correct |
52 |
Correct |
654 ms |
18912 KB |
Output is correct |
53 |
Correct |
638 ms |
18940 KB |
Output is correct |
54 |
Correct |
623 ms |
18884 KB |
Output is correct |
55 |
Correct |
766 ms |
19028 KB |
Output is correct |
56 |
Correct |
606 ms |
19056 KB |
Output is correct |
57 |
Correct |
784 ms |
18932 KB |
Output is correct |
58 |
Correct |
226 ms |
18936 KB |
Output is correct |
59 |
Correct |
235 ms |
18936 KB |
Output is correct |
60 |
Correct |
1 ms |
1484 KB |
Output is correct |
61 |
Correct |
1240 ms |
41340 KB |
Output is correct |
62 |
Correct |
1494 ms |
41404 KB |
Output is correct |
63 |
Correct |
1325 ms |
41292 KB |
Output is correct |
64 |
Correct |
1277 ms |
41408 KB |
Output is correct |
65 |
Correct |
1233 ms |
41404 KB |
Output is correct |
66 |
Correct |
1311 ms |
41468 KB |
Output is correct |
67 |
Correct |
1323 ms |
41428 KB |
Output is correct |
68 |
Correct |
1028 ms |
25552 KB |
Output is correct |
69 |
Correct |
765 ms |
22748 KB |
Output is correct |
70 |
Correct |
1 ms |
1484 KB |
Output is correct |