#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;
ll 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 |
2636 KB |
Output is correct |
2 |
Correct |
378 ms |
42512 KB |
Output is correct |
3 |
Correct |
372 ms |
48064 KB |
Output is correct |
4 |
Correct |
405 ms |
48188 KB |
Output is correct |
5 |
Correct |
402 ms |
48076 KB |
Output is correct |
6 |
Correct |
394 ms |
48036 KB |
Output is correct |
7 |
Correct |
400 ms |
48012 KB |
Output is correct |
8 |
Correct |
372 ms |
48132 KB |
Output is correct |
9 |
Correct |
306 ms |
32312 KB |
Output is correct |
10 |
Correct |
307 ms |
32232 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
56 ms |
9580 KB |
Output is correct |
2 |
Correct |
58 ms |
9716 KB |
Output is correct |
3 |
Correct |
58 ms |
9604 KB |
Output is correct |
4 |
Correct |
55 ms |
9840 KB |
Output is correct |
5 |
Correct |
56 ms |
9704 KB |
Output is correct |
6 |
Correct |
55 ms |
9672 KB |
Output is correct |
7 |
Correct |
56 ms |
9668 KB |
Output is correct |
8 |
Correct |
54 ms |
9796 KB |
Output is correct |
9 |
Correct |
56 ms |
9580 KB |
Output is correct |
10 |
Correct |
2 ms |
2636 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
56 ms |
9580 KB |
Output is correct |
2 |
Correct |
58 ms |
9716 KB |
Output is correct |
3 |
Correct |
58 ms |
9604 KB |
Output is correct |
4 |
Correct |
55 ms |
9840 KB |
Output is correct |
5 |
Correct |
56 ms |
9704 KB |
Output is correct |
6 |
Correct |
55 ms |
9672 KB |
Output is correct |
7 |
Correct |
56 ms |
9668 KB |
Output is correct |
8 |
Correct |
54 ms |
9796 KB |
Output is correct |
9 |
Correct |
56 ms |
9580 KB |
Output is correct |
10 |
Correct |
2 ms |
2636 KB |
Output is correct |
11 |
Correct |
113 ms |
9716 KB |
Output is correct |
12 |
Correct |
95 ms |
9668 KB |
Output is correct |
13 |
Correct |
94 ms |
9716 KB |
Output is correct |
14 |
Correct |
104 ms |
9712 KB |
Output is correct |
15 |
Correct |
96 ms |
9720 KB |
Output is correct |
16 |
Correct |
93 ms |
9776 KB |
Output is correct |
17 |
Correct |
91 ms |
9716 KB |
Output is correct |
18 |
Correct |
70 ms |
9712 KB |
Output is correct |
19 |
Correct |
71 ms |
9720 KB |
Output is correct |
20 |
Correct |
2 ms |
2636 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2636 KB |
Output is correct |
2 |
Correct |
2 ms |
2636 KB |
Output is correct |
3 |
Correct |
2 ms |
2636 KB |
Output is correct |
4 |
Correct |
2 ms |
2636 KB |
Output is correct |
5 |
Correct |
2 ms |
2636 KB |
Output is correct |
6 |
Correct |
2 ms |
2636 KB |
Output is correct |
7 |
Correct |
2 ms |
2636 KB |
Output is correct |
8 |
Correct |
2 ms |
2636 KB |
Output is correct |
9 |
Correct |
2 ms |
2636 KB |
Output is correct |
10 |
Correct |
2 ms |
2636 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2636 KB |
Output is correct |
2 |
Correct |
2 ms |
2636 KB |
Output is correct |
3 |
Correct |
2 ms |
2636 KB |
Output is correct |
4 |
Correct |
2 ms |
2636 KB |
Output is correct |
5 |
Correct |
2 ms |
2636 KB |
Output is correct |
6 |
Correct |
2 ms |
2636 KB |
Output is correct |
7 |
Correct |
2 ms |
2636 KB |
Output is correct |
8 |
Correct |
2 ms |
2636 KB |
Output is correct |
9 |
Correct |
2 ms |
2636 KB |
Output is correct |
10 |
Correct |
2 ms |
2636 KB |
Output is correct |
11 |
Correct |
14 ms |
3916 KB |
Output is correct |
12 |
Correct |
16 ms |
4044 KB |
Output is correct |
13 |
Correct |
18 ms |
3916 KB |
Output is correct |
14 |
Correct |
20 ms |
3920 KB |
Output is correct |
15 |
Correct |
15 ms |
3916 KB |
Output is correct |
16 |
Correct |
16 ms |
3916 KB |
Output is correct |
17 |
Correct |
15 ms |
3972 KB |
Output is correct |
18 |
Correct |
11 ms |
3276 KB |
Output is correct |
19 |
Correct |
6 ms |
2892 KB |
Output is correct |
20 |
Correct |
2 ms |
2636 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
56 ms |
9580 KB |
Output is correct |
2 |
Correct |
58 ms |
9716 KB |
Output is correct |
3 |
Correct |
58 ms |
9604 KB |
Output is correct |
4 |
Correct |
55 ms |
9840 KB |
Output is correct |
5 |
Correct |
56 ms |
9704 KB |
Output is correct |
6 |
Correct |
55 ms |
9672 KB |
Output is correct |
7 |
Correct |
56 ms |
9668 KB |
Output is correct |
8 |
Correct |
54 ms |
9796 KB |
Output is correct |
9 |
Correct |
56 ms |
9580 KB |
Output is correct |
10 |
Correct |
2 ms |
2636 KB |
Output is correct |
11 |
Correct |
113 ms |
9716 KB |
Output is correct |
12 |
Correct |
95 ms |
9668 KB |
Output is correct |
13 |
Correct |
94 ms |
9716 KB |
Output is correct |
14 |
Correct |
104 ms |
9712 KB |
Output is correct |
15 |
Correct |
96 ms |
9720 KB |
Output is correct |
16 |
Correct |
93 ms |
9776 KB |
Output is correct |
17 |
Correct |
91 ms |
9716 KB |
Output is correct |
18 |
Correct |
70 ms |
9712 KB |
Output is correct |
19 |
Correct |
71 ms |
9720 KB |
Output is correct |
20 |
Correct |
2 ms |
2636 KB |
Output is correct |
21 |
Correct |
662 ms |
21224 KB |
Output is correct |
22 |
Correct |
747 ms |
21836 KB |
Output is correct |
23 |
Correct |
654 ms |
21844 KB |
Output is correct |
24 |
Correct |
720 ms |
21796 KB |
Output is correct |
25 |
Correct |
629 ms |
21848 KB |
Output is correct |
26 |
Correct |
650 ms |
21844 KB |
Output is correct |
27 |
Correct |
650 ms |
21856 KB |
Output is correct |
28 |
Correct |
237 ms |
21728 KB |
Output is correct |
29 |
Correct |
219 ms |
21828 KB |
Output is correct |
30 |
Correct |
2 ms |
2636 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2636 KB |
Output is correct |
2 |
Correct |
378 ms |
42512 KB |
Output is correct |
3 |
Correct |
372 ms |
48064 KB |
Output is correct |
4 |
Correct |
405 ms |
48188 KB |
Output is correct |
5 |
Correct |
402 ms |
48076 KB |
Output is correct |
6 |
Correct |
394 ms |
48036 KB |
Output is correct |
7 |
Correct |
400 ms |
48012 KB |
Output is correct |
8 |
Correct |
372 ms |
48132 KB |
Output is correct |
9 |
Correct |
306 ms |
32312 KB |
Output is correct |
10 |
Correct |
307 ms |
32232 KB |
Output is correct |
11 |
Correct |
56 ms |
9580 KB |
Output is correct |
12 |
Correct |
58 ms |
9716 KB |
Output is correct |
13 |
Correct |
58 ms |
9604 KB |
Output is correct |
14 |
Correct |
55 ms |
9840 KB |
Output is correct |
15 |
Correct |
56 ms |
9704 KB |
Output is correct |
16 |
Correct |
55 ms |
9672 KB |
Output is correct |
17 |
Correct |
56 ms |
9668 KB |
Output is correct |
18 |
Correct |
54 ms |
9796 KB |
Output is correct |
19 |
Correct |
56 ms |
9580 KB |
Output is correct |
20 |
Correct |
2 ms |
2636 KB |
Output is correct |
21 |
Correct |
113 ms |
9716 KB |
Output is correct |
22 |
Correct |
95 ms |
9668 KB |
Output is correct |
23 |
Correct |
94 ms |
9716 KB |
Output is correct |
24 |
Correct |
104 ms |
9712 KB |
Output is correct |
25 |
Correct |
96 ms |
9720 KB |
Output is correct |
26 |
Correct |
93 ms |
9776 KB |
Output is correct |
27 |
Correct |
91 ms |
9716 KB |
Output is correct |
28 |
Correct |
70 ms |
9712 KB |
Output is correct |
29 |
Correct |
71 ms |
9720 KB |
Output is correct |
30 |
Correct |
2 ms |
2636 KB |
Output is correct |
31 |
Correct |
2 ms |
2636 KB |
Output is correct |
32 |
Correct |
2 ms |
2636 KB |
Output is correct |
33 |
Correct |
2 ms |
2636 KB |
Output is correct |
34 |
Correct |
2 ms |
2636 KB |
Output is correct |
35 |
Correct |
2 ms |
2636 KB |
Output is correct |
36 |
Correct |
2 ms |
2636 KB |
Output is correct |
37 |
Correct |
2 ms |
2636 KB |
Output is correct |
38 |
Correct |
2 ms |
2636 KB |
Output is correct |
39 |
Correct |
2 ms |
2636 KB |
Output is correct |
40 |
Correct |
2 ms |
2636 KB |
Output is correct |
41 |
Correct |
14 ms |
3916 KB |
Output is correct |
42 |
Correct |
16 ms |
4044 KB |
Output is correct |
43 |
Correct |
18 ms |
3916 KB |
Output is correct |
44 |
Correct |
20 ms |
3920 KB |
Output is correct |
45 |
Correct |
15 ms |
3916 KB |
Output is correct |
46 |
Correct |
16 ms |
3916 KB |
Output is correct |
47 |
Correct |
15 ms |
3972 KB |
Output is correct |
48 |
Correct |
11 ms |
3276 KB |
Output is correct |
49 |
Correct |
6 ms |
2892 KB |
Output is correct |
50 |
Correct |
2 ms |
2636 KB |
Output is correct |
51 |
Correct |
662 ms |
21224 KB |
Output is correct |
52 |
Correct |
747 ms |
21836 KB |
Output is correct |
53 |
Correct |
654 ms |
21844 KB |
Output is correct |
54 |
Correct |
720 ms |
21796 KB |
Output is correct |
55 |
Correct |
629 ms |
21848 KB |
Output is correct |
56 |
Correct |
650 ms |
21844 KB |
Output is correct |
57 |
Correct |
650 ms |
21856 KB |
Output is correct |
58 |
Correct |
237 ms |
21728 KB |
Output is correct |
59 |
Correct |
219 ms |
21828 KB |
Output is correct |
60 |
Correct |
2 ms |
2636 KB |
Output is correct |
61 |
Correct |
1445 ms |
48048 KB |
Output is correct |
62 |
Correct |
1292 ms |
48128 KB |
Output is correct |
63 |
Correct |
1289 ms |
48200 KB |
Output is correct |
64 |
Correct |
1280 ms |
48160 KB |
Output is correct |
65 |
Correct |
1344 ms |
48132 KB |
Output is correct |
66 |
Correct |
1345 ms |
48120 KB |
Output is correct |
67 |
Correct |
1312 ms |
48128 KB |
Output is correct |
68 |
Correct |
951 ms |
32368 KB |
Output is correct |
69 |
Correct |
780 ms |
25844 KB |
Output is correct |
70 |
Correct |
2 ms |
2636 KB |
Output is correct |