#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef pair<long long, int> elem;
typedef tree<elem,null_type,std::less<elem>,rb_tree_tag,tree_order_statistics_node_update> stat_tree;
constexpr int MAXN=300'000;
long long arr[MAXN];
int lefts[MAXN];
int main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int n;
cin>>n;
assert(3<=n&&n<=MAXN);
stat_tree st;
long long ans=0;
for(int i=0;i<n;++i){
cin>>arr[i];
assert(0<=arr[i]&&arr[i]<=1'000'000'000'000'000'000ll);
lefts[i]=st.order_of_key(make_pair(arr[i],0));
st.insert(make_pair(arr[i],i));
}
st.clear();
for(int i=n-1;i>=0;--i){
const int ct=st.order_of_key(make_pair(arr[i],0));
ans+=static_cast<long long>(ct)*lefts[i];
st.insert(make_pair(arr[i],i));
}
cout<<ans<<'\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
491 ms |
22648 KB |
Output is correct |
3 |
Correct |
493 ms |
22632 KB |
Output is correct |
4 |
Correct |
481 ms |
22648 KB |
Output is correct |
5 |
Correct |
489 ms |
22648 KB |
Output is correct |
6 |
Correct |
477 ms |
22648 KB |
Output is correct |
7 |
Correct |
489 ms |
22648 KB |
Output is correct |
8 |
Correct |
496 ms |
22648 KB |
Output is correct |
9 |
Correct |
494 ms |
22648 KB |
Output is correct |
10 |
Correct |
508 ms |
22648 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
319 ms |
22648 KB |
Output is correct |
2 |
Correct |
302 ms |
22648 KB |
Output is correct |
3 |
Correct |
301 ms |
22648 KB |
Output is correct |
4 |
Correct |
300 ms |
22648 KB |
Output is correct |
5 |
Correct |
296 ms |
22648 KB |
Output is correct |
6 |
Correct |
301 ms |
22648 KB |
Output is correct |
7 |
Correct |
332 ms |
22700 KB |
Output is correct |
8 |
Correct |
440 ms |
22648 KB |
Output is correct |
9 |
Correct |
438 ms |
22580 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
319 ms |
22648 KB |
Output is correct |
2 |
Correct |
302 ms |
22648 KB |
Output is correct |
3 |
Correct |
301 ms |
22648 KB |
Output is correct |
4 |
Correct |
300 ms |
22648 KB |
Output is correct |
5 |
Correct |
296 ms |
22648 KB |
Output is correct |
6 |
Correct |
301 ms |
22648 KB |
Output is correct |
7 |
Correct |
332 ms |
22700 KB |
Output is correct |
8 |
Correct |
440 ms |
22648 KB |
Output is correct |
9 |
Correct |
438 ms |
22580 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
11 |
Correct |
643 ms |
22752 KB |
Output is correct |
12 |
Correct |
627 ms |
22648 KB |
Output is correct |
13 |
Correct |
677 ms |
22624 KB |
Output is correct |
14 |
Correct |
669 ms |
22648 KB |
Output is correct |
15 |
Correct |
683 ms |
22648 KB |
Output is correct |
16 |
Correct |
685 ms |
22648 KB |
Output is correct |
17 |
Correct |
687 ms |
22696 KB |
Output is correct |
18 |
Correct |
449 ms |
22616 KB |
Output is correct |
19 |
Correct |
446 ms |
22648 KB |
Output is correct |
20 |
Correct |
5 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
6 ms |
376 KB |
Output is correct |
3 |
Correct |
6 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
380 KB |
Output is correct |
9 |
Correct |
5 ms |
376 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
6 ms |
376 KB |
Output is correct |
3 |
Correct |
6 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
380 KB |
Output is correct |
9 |
Correct |
5 ms |
376 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
11 |
Correct |
15 ms |
1020 KB |
Output is correct |
12 |
Correct |
16 ms |
1144 KB |
Output is correct |
13 |
Correct |
17 ms |
1144 KB |
Output is correct |
14 |
Correct |
15 ms |
1144 KB |
Output is correct |
15 |
Correct |
15 ms |
1144 KB |
Output is correct |
16 |
Correct |
17 ms |
1144 KB |
Output is correct |
17 |
Correct |
14 ms |
1144 KB |
Output is correct |
18 |
Correct |
16 ms |
1144 KB |
Output is correct |
19 |
Correct |
14 ms |
1120 KB |
Output is correct |
20 |
Correct |
5 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
319 ms |
22648 KB |
Output is correct |
2 |
Correct |
302 ms |
22648 KB |
Output is correct |
3 |
Correct |
301 ms |
22648 KB |
Output is correct |
4 |
Correct |
300 ms |
22648 KB |
Output is correct |
5 |
Correct |
296 ms |
22648 KB |
Output is correct |
6 |
Correct |
301 ms |
22648 KB |
Output is correct |
7 |
Correct |
332 ms |
22700 KB |
Output is correct |
8 |
Correct |
440 ms |
22648 KB |
Output is correct |
9 |
Correct |
438 ms |
22580 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
11 |
Correct |
643 ms |
22752 KB |
Output is correct |
12 |
Correct |
627 ms |
22648 KB |
Output is correct |
13 |
Correct |
677 ms |
22624 KB |
Output is correct |
14 |
Correct |
669 ms |
22648 KB |
Output is correct |
15 |
Correct |
683 ms |
22648 KB |
Output is correct |
16 |
Correct |
685 ms |
22648 KB |
Output is correct |
17 |
Correct |
687 ms |
22696 KB |
Output is correct |
18 |
Correct |
449 ms |
22616 KB |
Output is correct |
19 |
Correct |
446 ms |
22648 KB |
Output is correct |
20 |
Correct |
5 ms |
376 KB |
Output is correct |
21 |
Correct |
789 ms |
22652 KB |
Output is correct |
22 |
Correct |
834 ms |
22692 KB |
Output is correct |
23 |
Correct |
846 ms |
22604 KB |
Output is correct |
24 |
Correct |
811 ms |
22700 KB |
Output is correct |
25 |
Correct |
841 ms |
22664 KB |
Output is correct |
26 |
Correct |
844 ms |
22620 KB |
Output is correct |
27 |
Correct |
843 ms |
22648 KB |
Output is correct |
28 |
Correct |
497 ms |
22676 KB |
Output is correct |
29 |
Correct |
487 ms |
22704 KB |
Output is correct |
30 |
Correct |
5 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
491 ms |
22648 KB |
Output is correct |
3 |
Correct |
493 ms |
22632 KB |
Output is correct |
4 |
Correct |
481 ms |
22648 KB |
Output is correct |
5 |
Correct |
489 ms |
22648 KB |
Output is correct |
6 |
Correct |
477 ms |
22648 KB |
Output is correct |
7 |
Correct |
489 ms |
22648 KB |
Output is correct |
8 |
Correct |
496 ms |
22648 KB |
Output is correct |
9 |
Correct |
494 ms |
22648 KB |
Output is correct |
10 |
Correct |
508 ms |
22648 KB |
Output is correct |
11 |
Correct |
319 ms |
22648 KB |
Output is correct |
12 |
Correct |
302 ms |
22648 KB |
Output is correct |
13 |
Correct |
301 ms |
22648 KB |
Output is correct |
14 |
Correct |
300 ms |
22648 KB |
Output is correct |
15 |
Correct |
296 ms |
22648 KB |
Output is correct |
16 |
Correct |
301 ms |
22648 KB |
Output is correct |
17 |
Correct |
332 ms |
22700 KB |
Output is correct |
18 |
Correct |
440 ms |
22648 KB |
Output is correct |
19 |
Correct |
438 ms |
22580 KB |
Output is correct |
20 |
Correct |
5 ms |
376 KB |
Output is correct |
21 |
Correct |
643 ms |
22752 KB |
Output is correct |
22 |
Correct |
627 ms |
22648 KB |
Output is correct |
23 |
Correct |
677 ms |
22624 KB |
Output is correct |
24 |
Correct |
669 ms |
22648 KB |
Output is correct |
25 |
Correct |
683 ms |
22648 KB |
Output is correct |
26 |
Correct |
685 ms |
22648 KB |
Output is correct |
27 |
Correct |
687 ms |
22696 KB |
Output is correct |
28 |
Correct |
449 ms |
22616 KB |
Output is correct |
29 |
Correct |
446 ms |
22648 KB |
Output is correct |
30 |
Correct |
5 ms |
376 KB |
Output is correct |
31 |
Correct |
5 ms |
376 KB |
Output is correct |
32 |
Correct |
6 ms |
376 KB |
Output is correct |
33 |
Correct |
6 ms |
376 KB |
Output is correct |
34 |
Correct |
5 ms |
376 KB |
Output is correct |
35 |
Correct |
5 ms |
376 KB |
Output is correct |
36 |
Correct |
5 ms |
376 KB |
Output is correct |
37 |
Correct |
5 ms |
376 KB |
Output is correct |
38 |
Correct |
5 ms |
380 KB |
Output is correct |
39 |
Correct |
5 ms |
376 KB |
Output is correct |
40 |
Correct |
5 ms |
376 KB |
Output is correct |
41 |
Correct |
15 ms |
1020 KB |
Output is correct |
42 |
Correct |
16 ms |
1144 KB |
Output is correct |
43 |
Correct |
17 ms |
1144 KB |
Output is correct |
44 |
Correct |
15 ms |
1144 KB |
Output is correct |
45 |
Correct |
15 ms |
1144 KB |
Output is correct |
46 |
Correct |
17 ms |
1144 KB |
Output is correct |
47 |
Correct |
14 ms |
1144 KB |
Output is correct |
48 |
Correct |
16 ms |
1144 KB |
Output is correct |
49 |
Correct |
14 ms |
1120 KB |
Output is correct |
50 |
Correct |
5 ms |
376 KB |
Output is correct |
51 |
Correct |
789 ms |
22652 KB |
Output is correct |
52 |
Correct |
834 ms |
22692 KB |
Output is correct |
53 |
Correct |
846 ms |
22604 KB |
Output is correct |
54 |
Correct |
811 ms |
22700 KB |
Output is correct |
55 |
Correct |
841 ms |
22664 KB |
Output is correct |
56 |
Correct |
844 ms |
22620 KB |
Output is correct |
57 |
Correct |
843 ms |
22648 KB |
Output is correct |
58 |
Correct |
497 ms |
22676 KB |
Output is correct |
59 |
Correct |
487 ms |
22704 KB |
Output is correct |
60 |
Correct |
5 ms |
376 KB |
Output is correct |
61 |
Correct |
884 ms |
22624 KB |
Output is correct |
62 |
Correct |
942 ms |
22572 KB |
Output is correct |
63 |
Correct |
885 ms |
22648 KB |
Output is correct |
64 |
Correct |
880 ms |
22660 KB |
Output is correct |
65 |
Correct |
897 ms |
22700 KB |
Output is correct |
66 |
Correct |
919 ms |
22612 KB |
Output is correct |
67 |
Correct |
866 ms |
22600 KB |
Output is correct |
68 |
Correct |
909 ms |
22648 KB |
Output is correct |
69 |
Correct |
813 ms |
22692 KB |
Output is correct |
70 |
Correct |
5 ms |
376 KB |
Output is correct |