#include<bits/stdc++.h>
#define ll long long
#define pii pair<ll,int>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define oset tree<pii,null_type,less<pii>,rb_tree_tag,tree_order_statistics_node_update>
ll a[300005],L[300005],R[300005];
main() {
oset s;
int n;
cin >> n;
for (int i = 1; i <= n; i++)
cin >> a[i];
for (int i =1 ; i <= n; i++) {
L[i] = s.order_of_key({a[i],0});
s.insert({a[i],i});
}
s.clear();
ll ans = 0;
for (int i = n; i > 0; i--) {
R[i] = s.order_of_key({a[i],0});
s.insert({a[i],i});
ans += (ll)L[i]*R[i];
}
cout << ans;
}
Compilation message
Mountains.cpp:10:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
10 | main() {
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
926 ms |
31768 KB |
Output is correct |
3 |
Correct |
937 ms |
31696 KB |
Output is correct |
4 |
Correct |
917 ms |
31796 KB |
Output is correct |
5 |
Correct |
927 ms |
31688 KB |
Output is correct |
6 |
Correct |
933 ms |
31904 KB |
Output is correct |
7 |
Correct |
940 ms |
31728 KB |
Output is correct |
8 |
Correct |
969 ms |
31684 KB |
Output is correct |
9 |
Correct |
934 ms |
31736 KB |
Output is correct |
10 |
Correct |
929 ms |
31768 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
373 ms |
26736 KB |
Output is correct |
2 |
Correct |
381 ms |
26744 KB |
Output is correct |
3 |
Correct |
376 ms |
26744 KB |
Output is correct |
4 |
Correct |
383 ms |
26744 KB |
Output is correct |
5 |
Correct |
377 ms |
26800 KB |
Output is correct |
6 |
Correct |
386 ms |
26744 KB |
Output is correct |
7 |
Correct |
380 ms |
26744 KB |
Output is correct |
8 |
Correct |
538 ms |
26752 KB |
Output is correct |
9 |
Correct |
563 ms |
26748 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
373 ms |
26736 KB |
Output is correct |
2 |
Correct |
381 ms |
26744 KB |
Output is correct |
3 |
Correct |
376 ms |
26744 KB |
Output is correct |
4 |
Correct |
383 ms |
26744 KB |
Output is correct |
5 |
Correct |
377 ms |
26800 KB |
Output is correct |
6 |
Correct |
386 ms |
26744 KB |
Output is correct |
7 |
Correct |
380 ms |
26744 KB |
Output is correct |
8 |
Correct |
538 ms |
26752 KB |
Output is correct |
9 |
Correct |
563 ms |
26748 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
734 ms |
26984 KB |
Output is correct |
12 |
Correct |
714 ms |
27000 KB |
Output is correct |
13 |
Correct |
693 ms |
27128 KB |
Output is correct |
14 |
Correct |
669 ms |
27260 KB |
Output is correct |
15 |
Correct |
709 ms |
27000 KB |
Output is correct |
16 |
Correct |
712 ms |
27004 KB |
Output is correct |
17 |
Correct |
714 ms |
27000 KB |
Output is correct |
18 |
Correct |
567 ms |
27000 KB |
Output is correct |
19 |
Correct |
569 ms |
27000 KB |
Output is correct |
20 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
23 ms |
1408 KB |
Output is correct |
12 |
Correct |
24 ms |
1408 KB |
Output is correct |
13 |
Correct |
24 ms |
1408 KB |
Output is correct |
14 |
Correct |
24 ms |
1408 KB |
Output is correct |
15 |
Correct |
23 ms |
1400 KB |
Output is correct |
16 |
Correct |
23 ms |
1408 KB |
Output is correct |
17 |
Correct |
23 ms |
1408 KB |
Output is correct |
18 |
Correct |
23 ms |
1408 KB |
Output is correct |
19 |
Correct |
13 ms |
1280 KB |
Output is correct |
20 |
Correct |
0 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
373 ms |
26736 KB |
Output is correct |
2 |
Correct |
381 ms |
26744 KB |
Output is correct |
3 |
Correct |
376 ms |
26744 KB |
Output is correct |
4 |
Correct |
383 ms |
26744 KB |
Output is correct |
5 |
Correct |
377 ms |
26800 KB |
Output is correct |
6 |
Correct |
386 ms |
26744 KB |
Output is correct |
7 |
Correct |
380 ms |
26744 KB |
Output is correct |
8 |
Correct |
538 ms |
26752 KB |
Output is correct |
9 |
Correct |
563 ms |
26748 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
734 ms |
26984 KB |
Output is correct |
12 |
Correct |
714 ms |
27000 KB |
Output is correct |
13 |
Correct |
693 ms |
27128 KB |
Output is correct |
14 |
Correct |
669 ms |
27260 KB |
Output is correct |
15 |
Correct |
709 ms |
27000 KB |
Output is correct |
16 |
Correct |
712 ms |
27004 KB |
Output is correct |
17 |
Correct |
714 ms |
27000 KB |
Output is correct |
18 |
Correct |
567 ms |
27000 KB |
Output is correct |
19 |
Correct |
569 ms |
27000 KB |
Output is correct |
20 |
Correct |
1 ms |
384 KB |
Output is correct |
21 |
Correct |
895 ms |
27920 KB |
Output is correct |
22 |
Correct |
898 ms |
28024 KB |
Output is correct |
23 |
Correct |
905 ms |
28076 KB |
Output is correct |
24 |
Correct |
896 ms |
28000 KB |
Output is correct |
25 |
Correct |
903 ms |
28024 KB |
Output is correct |
26 |
Correct |
904 ms |
28004 KB |
Output is correct |
27 |
Correct |
931 ms |
27896 KB |
Output is correct |
28 |
Correct |
662 ms |
27988 KB |
Output is correct |
29 |
Correct |
677 ms |
27936 KB |
Output is correct |
30 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
926 ms |
31768 KB |
Output is correct |
3 |
Correct |
937 ms |
31696 KB |
Output is correct |
4 |
Correct |
917 ms |
31796 KB |
Output is correct |
5 |
Correct |
927 ms |
31688 KB |
Output is correct |
6 |
Correct |
933 ms |
31904 KB |
Output is correct |
7 |
Correct |
940 ms |
31728 KB |
Output is correct |
8 |
Correct |
969 ms |
31684 KB |
Output is correct |
9 |
Correct |
934 ms |
31736 KB |
Output is correct |
10 |
Correct |
929 ms |
31768 KB |
Output is correct |
11 |
Correct |
373 ms |
26736 KB |
Output is correct |
12 |
Correct |
381 ms |
26744 KB |
Output is correct |
13 |
Correct |
376 ms |
26744 KB |
Output is correct |
14 |
Correct |
383 ms |
26744 KB |
Output is correct |
15 |
Correct |
377 ms |
26800 KB |
Output is correct |
16 |
Correct |
386 ms |
26744 KB |
Output is correct |
17 |
Correct |
380 ms |
26744 KB |
Output is correct |
18 |
Correct |
538 ms |
26752 KB |
Output is correct |
19 |
Correct |
563 ms |
26748 KB |
Output is correct |
20 |
Correct |
1 ms |
384 KB |
Output is correct |
21 |
Correct |
734 ms |
26984 KB |
Output is correct |
22 |
Correct |
714 ms |
27000 KB |
Output is correct |
23 |
Correct |
693 ms |
27128 KB |
Output is correct |
24 |
Correct |
669 ms |
27260 KB |
Output is correct |
25 |
Correct |
709 ms |
27000 KB |
Output is correct |
26 |
Correct |
712 ms |
27004 KB |
Output is correct |
27 |
Correct |
714 ms |
27000 KB |
Output is correct |
28 |
Correct |
567 ms |
27000 KB |
Output is correct |
29 |
Correct |
569 ms |
27000 KB |
Output is correct |
30 |
Correct |
1 ms |
384 KB |
Output is correct |
31 |
Correct |
2 ms |
384 KB |
Output is correct |
32 |
Correct |
2 ms |
384 KB |
Output is correct |
33 |
Correct |
1 ms |
384 KB |
Output is correct |
34 |
Correct |
2 ms |
384 KB |
Output is correct |
35 |
Correct |
1 ms |
384 KB |
Output is correct |
36 |
Correct |
1 ms |
384 KB |
Output is correct |
37 |
Correct |
2 ms |
384 KB |
Output is correct |
38 |
Correct |
1 ms |
384 KB |
Output is correct |
39 |
Correct |
1 ms |
384 KB |
Output is correct |
40 |
Correct |
1 ms |
384 KB |
Output is correct |
41 |
Correct |
23 ms |
1408 KB |
Output is correct |
42 |
Correct |
24 ms |
1408 KB |
Output is correct |
43 |
Correct |
24 ms |
1408 KB |
Output is correct |
44 |
Correct |
24 ms |
1408 KB |
Output is correct |
45 |
Correct |
23 ms |
1400 KB |
Output is correct |
46 |
Correct |
23 ms |
1408 KB |
Output is correct |
47 |
Correct |
23 ms |
1408 KB |
Output is correct |
48 |
Correct |
23 ms |
1408 KB |
Output is correct |
49 |
Correct |
13 ms |
1280 KB |
Output is correct |
50 |
Correct |
0 ms |
384 KB |
Output is correct |
51 |
Correct |
895 ms |
27920 KB |
Output is correct |
52 |
Correct |
898 ms |
28024 KB |
Output is correct |
53 |
Correct |
905 ms |
28076 KB |
Output is correct |
54 |
Correct |
896 ms |
28000 KB |
Output is correct |
55 |
Correct |
903 ms |
28024 KB |
Output is correct |
56 |
Correct |
904 ms |
28004 KB |
Output is correct |
57 |
Correct |
931 ms |
27896 KB |
Output is correct |
58 |
Correct |
662 ms |
27988 KB |
Output is correct |
59 |
Correct |
677 ms |
27936 KB |
Output is correct |
60 |
Correct |
1 ms |
384 KB |
Output is correct |
61 |
Correct |
1131 ms |
31852 KB |
Output is correct |
62 |
Correct |
1162 ms |
32084 KB |
Output is correct |
63 |
Correct |
1143 ms |
31864 KB |
Output is correct |
64 |
Correct |
1142 ms |
31868 KB |
Output is correct |
65 |
Correct |
1162 ms |
31992 KB |
Output is correct |
66 |
Correct |
1117 ms |
31736 KB |
Output is correct |
67 |
Correct |
1119 ms |
31864 KB |
Output is correct |
68 |
Correct |
1118 ms |
32048 KB |
Output is correct |
69 |
Correct |
848 ms |
28152 KB |
Output is correct |
70 |
Correct |
1 ms |
384 KB |
Output is correct |