#include <bits/stdc++.h>
using namespace std;
#define ar array
#define ll long long
const int MAX_N = 1e5 + 1;
const ll MOD = 1e9 + 7;
const ll INF = 1e9;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template <class T> using ordered_set = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <class K, class V> using ordered_map = tree<K, V, less<K>, rb_tree_tag, tree_order_statistics_node_update>;
void solve() {
int n; cin >> n;
vector<ll> a(n);
for (ll &x : a) cin >> x;
vector<ll> lb(n), rb(n);
ordered_set<ar<ll,2>> os;
for (int i = 0; i < n; i++) {
lb[i] = os.order_of_key({a[i], 0});
os.insert({a[i], i});
}
os.clear();
for (int i = n - 1; i >= 0; i--) {
rb[i] = os.order_of_key({a[i], 0});
os.insert({a[i], i});
}
ll ans = 0;
for (int i = 0; i < n; i++) ans += lb[i] * rb[i];
cout << ans << "\n";
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int tc = 1;
// cin >> tc;
for (int t = 1; t <= tc; t++) {
// cout << "Case #" << t << ": ";
solve();
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
497 ms |
26688 KB |
Output is correct |
3 |
Correct |
508 ms |
31724 KB |
Output is correct |
4 |
Correct |
500 ms |
31852 KB |
Output is correct |
5 |
Correct |
511 ms |
31852 KB |
Output is correct |
6 |
Correct |
519 ms |
31852 KB |
Output is correct |
7 |
Correct |
498 ms |
31852 KB |
Output is correct |
8 |
Correct |
508 ms |
31852 KB |
Output is correct |
9 |
Correct |
507 ms |
31852 KB |
Output is correct |
10 |
Correct |
501 ms |
31724 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
372 ms |
26732 KB |
Output is correct |
2 |
Correct |
368 ms |
26732 KB |
Output is correct |
3 |
Correct |
373 ms |
26860 KB |
Output is correct |
4 |
Correct |
375 ms |
26732 KB |
Output is correct |
5 |
Correct |
379 ms |
26780 KB |
Output is correct |
6 |
Correct |
426 ms |
26852 KB |
Output is correct |
7 |
Correct |
392 ms |
26732 KB |
Output is correct |
8 |
Correct |
441 ms |
26832 KB |
Output is correct |
9 |
Correct |
460 ms |
26732 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
372 ms |
26732 KB |
Output is correct |
2 |
Correct |
368 ms |
26732 KB |
Output is correct |
3 |
Correct |
373 ms |
26860 KB |
Output is correct |
4 |
Correct |
375 ms |
26732 KB |
Output is correct |
5 |
Correct |
379 ms |
26780 KB |
Output is correct |
6 |
Correct |
426 ms |
26852 KB |
Output is correct |
7 |
Correct |
392 ms |
26732 KB |
Output is correct |
8 |
Correct |
441 ms |
26832 KB |
Output is correct |
9 |
Correct |
460 ms |
26732 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
696 ms |
27100 KB |
Output is correct |
12 |
Correct |
694 ms |
27188 KB |
Output is correct |
13 |
Correct |
685 ms |
27116 KB |
Output is correct |
14 |
Correct |
667 ms |
27116 KB |
Output is correct |
15 |
Correct |
660 ms |
27116 KB |
Output is correct |
16 |
Correct |
662 ms |
27264 KB |
Output is correct |
17 |
Correct |
669 ms |
27112 KB |
Output is correct |
18 |
Correct |
463 ms |
27244 KB |
Output is correct |
19 |
Correct |
465 ms |
27016 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
11 ms |
1388 KB |
Output is correct |
12 |
Correct |
11 ms |
1388 KB |
Output is correct |
13 |
Correct |
12 ms |
1388 KB |
Output is correct |
14 |
Correct |
11 ms |
1388 KB |
Output is correct |
15 |
Correct |
11 ms |
1388 KB |
Output is correct |
16 |
Correct |
11 ms |
1388 KB |
Output is correct |
17 |
Correct |
11 ms |
1388 KB |
Output is correct |
18 |
Correct |
11 ms |
1388 KB |
Output is correct |
19 |
Correct |
10 ms |
1280 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
372 ms |
26732 KB |
Output is correct |
2 |
Correct |
368 ms |
26732 KB |
Output is correct |
3 |
Correct |
373 ms |
26860 KB |
Output is correct |
4 |
Correct |
375 ms |
26732 KB |
Output is correct |
5 |
Correct |
379 ms |
26780 KB |
Output is correct |
6 |
Correct |
426 ms |
26852 KB |
Output is correct |
7 |
Correct |
392 ms |
26732 KB |
Output is correct |
8 |
Correct |
441 ms |
26832 KB |
Output is correct |
9 |
Correct |
460 ms |
26732 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
696 ms |
27100 KB |
Output is correct |
12 |
Correct |
694 ms |
27188 KB |
Output is correct |
13 |
Correct |
685 ms |
27116 KB |
Output is correct |
14 |
Correct |
667 ms |
27116 KB |
Output is correct |
15 |
Correct |
660 ms |
27116 KB |
Output is correct |
16 |
Correct |
662 ms |
27264 KB |
Output is correct |
17 |
Correct |
669 ms |
27112 KB |
Output is correct |
18 |
Correct |
463 ms |
27244 KB |
Output is correct |
19 |
Correct |
465 ms |
27016 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
21 |
Correct |
878 ms |
28012 KB |
Output is correct |
22 |
Correct |
844 ms |
28140 KB |
Output is correct |
23 |
Correct |
863 ms |
28080 KB |
Output is correct |
24 |
Correct |
842 ms |
28012 KB |
Output is correct |
25 |
Correct |
848 ms |
28012 KB |
Output is correct |
26 |
Correct |
841 ms |
28196 KB |
Output is correct |
27 |
Correct |
858 ms |
28012 KB |
Output is correct |
28 |
Correct |
475 ms |
28012 KB |
Output is correct |
29 |
Correct |
471 ms |
28012 KB |
Output is correct |
30 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
497 ms |
26688 KB |
Output is correct |
3 |
Correct |
508 ms |
31724 KB |
Output is correct |
4 |
Correct |
500 ms |
31852 KB |
Output is correct |
5 |
Correct |
511 ms |
31852 KB |
Output is correct |
6 |
Correct |
519 ms |
31852 KB |
Output is correct |
7 |
Correct |
498 ms |
31852 KB |
Output is correct |
8 |
Correct |
508 ms |
31852 KB |
Output is correct |
9 |
Correct |
507 ms |
31852 KB |
Output is correct |
10 |
Correct |
501 ms |
31724 KB |
Output is correct |
11 |
Correct |
372 ms |
26732 KB |
Output is correct |
12 |
Correct |
368 ms |
26732 KB |
Output is correct |
13 |
Correct |
373 ms |
26860 KB |
Output is correct |
14 |
Correct |
375 ms |
26732 KB |
Output is correct |
15 |
Correct |
379 ms |
26780 KB |
Output is correct |
16 |
Correct |
426 ms |
26852 KB |
Output is correct |
17 |
Correct |
392 ms |
26732 KB |
Output is correct |
18 |
Correct |
441 ms |
26832 KB |
Output is correct |
19 |
Correct |
460 ms |
26732 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
21 |
Correct |
696 ms |
27100 KB |
Output is correct |
22 |
Correct |
694 ms |
27188 KB |
Output is correct |
23 |
Correct |
685 ms |
27116 KB |
Output is correct |
24 |
Correct |
667 ms |
27116 KB |
Output is correct |
25 |
Correct |
660 ms |
27116 KB |
Output is correct |
26 |
Correct |
662 ms |
27264 KB |
Output is correct |
27 |
Correct |
669 ms |
27112 KB |
Output is correct |
28 |
Correct |
463 ms |
27244 KB |
Output is correct |
29 |
Correct |
465 ms |
27016 KB |
Output is correct |
30 |
Correct |
1 ms |
364 KB |
Output is correct |
31 |
Correct |
1 ms |
364 KB |
Output is correct |
32 |
Correct |
1 ms |
364 KB |
Output is correct |
33 |
Correct |
1 ms |
364 KB |
Output is correct |
34 |
Correct |
1 ms |
364 KB |
Output is correct |
35 |
Correct |
1 ms |
364 KB |
Output is correct |
36 |
Correct |
1 ms |
364 KB |
Output is correct |
37 |
Correct |
1 ms |
364 KB |
Output is correct |
38 |
Correct |
1 ms |
364 KB |
Output is correct |
39 |
Correct |
1 ms |
364 KB |
Output is correct |
40 |
Correct |
1 ms |
364 KB |
Output is correct |
41 |
Correct |
11 ms |
1388 KB |
Output is correct |
42 |
Correct |
11 ms |
1388 KB |
Output is correct |
43 |
Correct |
12 ms |
1388 KB |
Output is correct |
44 |
Correct |
11 ms |
1388 KB |
Output is correct |
45 |
Correct |
11 ms |
1388 KB |
Output is correct |
46 |
Correct |
11 ms |
1388 KB |
Output is correct |
47 |
Correct |
11 ms |
1388 KB |
Output is correct |
48 |
Correct |
11 ms |
1388 KB |
Output is correct |
49 |
Correct |
10 ms |
1280 KB |
Output is correct |
50 |
Correct |
1 ms |
364 KB |
Output is correct |
51 |
Correct |
878 ms |
28012 KB |
Output is correct |
52 |
Correct |
844 ms |
28140 KB |
Output is correct |
53 |
Correct |
863 ms |
28080 KB |
Output is correct |
54 |
Correct |
842 ms |
28012 KB |
Output is correct |
55 |
Correct |
848 ms |
28012 KB |
Output is correct |
56 |
Correct |
841 ms |
28196 KB |
Output is correct |
57 |
Correct |
858 ms |
28012 KB |
Output is correct |
58 |
Correct |
475 ms |
28012 KB |
Output is correct |
59 |
Correct |
471 ms |
28012 KB |
Output is correct |
60 |
Correct |
1 ms |
364 KB |
Output is correct |
61 |
Correct |
824 ms |
31652 KB |
Output is correct |
62 |
Correct |
855 ms |
31852 KB |
Output is correct |
63 |
Correct |
800 ms |
32000 KB |
Output is correct |
64 |
Correct |
805 ms |
31852 KB |
Output is correct |
65 |
Correct |
804 ms |
31724 KB |
Output is correct |
66 |
Correct |
813 ms |
31852 KB |
Output is correct |
67 |
Correct |
812 ms |
31980 KB |
Output is correct |
68 |
Correct |
838 ms |
31724 KB |
Output is correct |
69 |
Correct |
834 ms |
28156 KB |
Output is correct |
70 |
Correct |
1 ms |
364 KB |
Output is correct |