// bayemirov
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef tree<
ll,
null_type,
less_equal<ll>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
const int N = 4e5;
int n;
ll h[N], ans;
ordered_set a, b;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> n;
for (int i = 0; i < n; i++) {
cin >> h[i];
if (i > 1)
b.insert(h[i]);
}
a.insert(h[0]);
for (int i = 1; i < n; i++) {
int cnt_x = a.order_of_key(h[i]);
int cnt_z = b.order_of_key(h[i]);
//cout << i << ' ' << cnt_x << ' ' << cnt_z << "\n";
ans += cnt_x*1ll*cnt_z;
a.insert(h[i]);
b.erase(b.find_by_order(b.order_of_key(h[i+1])));
}
cout << ans;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
497 ms |
21468 KB |
Output is correct |
3 |
Correct |
496 ms |
21604 KB |
Output is correct |
4 |
Correct |
520 ms |
21760 KB |
Output is correct |
5 |
Correct |
496 ms |
21696 KB |
Output is correct |
6 |
Correct |
501 ms |
21908 KB |
Output is correct |
7 |
Correct |
509 ms |
21580 KB |
Output is correct |
8 |
Correct |
492 ms |
21620 KB |
Output is correct |
9 |
Correct |
509 ms |
21580 KB |
Output is correct |
10 |
Correct |
503 ms |
21668 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
321 ms |
21496 KB |
Output is correct |
2 |
Correct |
315 ms |
21680 KB |
Output is correct |
3 |
Correct |
297 ms |
21576 KB |
Output is correct |
4 |
Correct |
315 ms |
21672 KB |
Output is correct |
5 |
Correct |
323 ms |
21636 KB |
Output is correct |
6 |
Correct |
315 ms |
21568 KB |
Output is correct |
7 |
Correct |
305 ms |
21636 KB |
Output is correct |
8 |
Correct |
443 ms |
21528 KB |
Output is correct |
9 |
Correct |
448 ms |
21636 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
321 ms |
21496 KB |
Output is correct |
2 |
Correct |
315 ms |
21680 KB |
Output is correct |
3 |
Correct |
297 ms |
21576 KB |
Output is correct |
4 |
Correct |
315 ms |
21672 KB |
Output is correct |
5 |
Correct |
323 ms |
21636 KB |
Output is correct |
6 |
Correct |
315 ms |
21568 KB |
Output is correct |
7 |
Correct |
305 ms |
21636 KB |
Output is correct |
8 |
Correct |
443 ms |
21528 KB |
Output is correct |
9 |
Correct |
448 ms |
21636 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
616 ms |
21740 KB |
Output is correct |
12 |
Correct |
622 ms |
21700 KB |
Output is correct |
13 |
Correct |
637 ms |
21696 KB |
Output is correct |
14 |
Correct |
611 ms |
21708 KB |
Output is correct |
15 |
Correct |
628 ms |
21708 KB |
Output is correct |
16 |
Correct |
638 ms |
21704 KB |
Output is correct |
17 |
Correct |
625 ms |
21700 KB |
Output is correct |
18 |
Correct |
464 ms |
21696 KB |
Output is correct |
19 |
Correct |
462 ms |
21668 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
324 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
324 KB |
Output is correct |
11 |
Correct |
12 ms |
1108 KB |
Output is correct |
12 |
Correct |
11 ms |
1160 KB |
Output is correct |
13 |
Correct |
11 ms |
1108 KB |
Output is correct |
14 |
Correct |
11 ms |
1096 KB |
Output is correct |
15 |
Correct |
11 ms |
1112 KB |
Output is correct |
16 |
Correct |
11 ms |
1108 KB |
Output is correct |
17 |
Correct |
13 ms |
1108 KB |
Output is correct |
18 |
Correct |
12 ms |
1236 KB |
Output is correct |
19 |
Correct |
10 ms |
1028 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
321 ms |
21496 KB |
Output is correct |
2 |
Correct |
315 ms |
21680 KB |
Output is correct |
3 |
Correct |
297 ms |
21576 KB |
Output is correct |
4 |
Correct |
315 ms |
21672 KB |
Output is correct |
5 |
Correct |
323 ms |
21636 KB |
Output is correct |
6 |
Correct |
315 ms |
21568 KB |
Output is correct |
7 |
Correct |
305 ms |
21636 KB |
Output is correct |
8 |
Correct |
443 ms |
21528 KB |
Output is correct |
9 |
Correct |
448 ms |
21636 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
616 ms |
21740 KB |
Output is correct |
12 |
Correct |
622 ms |
21700 KB |
Output is correct |
13 |
Correct |
637 ms |
21696 KB |
Output is correct |
14 |
Correct |
611 ms |
21708 KB |
Output is correct |
15 |
Correct |
628 ms |
21708 KB |
Output is correct |
16 |
Correct |
638 ms |
21704 KB |
Output is correct |
17 |
Correct |
625 ms |
21700 KB |
Output is correct |
18 |
Correct |
464 ms |
21696 KB |
Output is correct |
19 |
Correct |
462 ms |
21668 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
832 ms |
21700 KB |
Output is correct |
22 |
Correct |
839 ms |
21708 KB |
Output is correct |
23 |
Correct |
836 ms |
21760 KB |
Output is correct |
24 |
Correct |
906 ms |
21700 KB |
Output is correct |
25 |
Correct |
840 ms |
21704 KB |
Output is correct |
26 |
Correct |
874 ms |
21704 KB |
Output is correct |
27 |
Correct |
838 ms |
21808 KB |
Output is correct |
28 |
Correct |
475 ms |
21704 KB |
Output is correct |
29 |
Correct |
473 ms |
21708 KB |
Output is correct |
30 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
497 ms |
21468 KB |
Output is correct |
3 |
Correct |
496 ms |
21604 KB |
Output is correct |
4 |
Correct |
520 ms |
21760 KB |
Output is correct |
5 |
Correct |
496 ms |
21696 KB |
Output is correct |
6 |
Correct |
501 ms |
21908 KB |
Output is correct |
7 |
Correct |
509 ms |
21580 KB |
Output is correct |
8 |
Correct |
492 ms |
21620 KB |
Output is correct |
9 |
Correct |
509 ms |
21580 KB |
Output is correct |
10 |
Correct |
503 ms |
21668 KB |
Output is correct |
11 |
Correct |
321 ms |
21496 KB |
Output is correct |
12 |
Correct |
315 ms |
21680 KB |
Output is correct |
13 |
Correct |
297 ms |
21576 KB |
Output is correct |
14 |
Correct |
315 ms |
21672 KB |
Output is correct |
15 |
Correct |
323 ms |
21636 KB |
Output is correct |
16 |
Correct |
315 ms |
21568 KB |
Output is correct |
17 |
Correct |
305 ms |
21636 KB |
Output is correct |
18 |
Correct |
443 ms |
21528 KB |
Output is correct |
19 |
Correct |
448 ms |
21636 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
616 ms |
21740 KB |
Output is correct |
22 |
Correct |
622 ms |
21700 KB |
Output is correct |
23 |
Correct |
637 ms |
21696 KB |
Output is correct |
24 |
Correct |
611 ms |
21708 KB |
Output is correct |
25 |
Correct |
628 ms |
21708 KB |
Output is correct |
26 |
Correct |
638 ms |
21704 KB |
Output is correct |
27 |
Correct |
625 ms |
21700 KB |
Output is correct |
28 |
Correct |
464 ms |
21696 KB |
Output is correct |
29 |
Correct |
462 ms |
21668 KB |
Output is correct |
30 |
Correct |
1 ms |
212 KB |
Output is correct |
31 |
Correct |
1 ms |
340 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
1 ms |
340 KB |
Output is correct |
34 |
Correct |
1 ms |
340 KB |
Output is correct |
35 |
Correct |
1 ms |
340 KB |
Output is correct |
36 |
Correct |
1 ms |
340 KB |
Output is correct |
37 |
Correct |
1 ms |
340 KB |
Output is correct |
38 |
Correct |
1 ms |
340 KB |
Output is correct |
39 |
Correct |
1 ms |
340 KB |
Output is correct |
40 |
Correct |
1 ms |
324 KB |
Output is correct |
41 |
Correct |
12 ms |
1108 KB |
Output is correct |
42 |
Correct |
11 ms |
1160 KB |
Output is correct |
43 |
Correct |
11 ms |
1108 KB |
Output is correct |
44 |
Correct |
11 ms |
1096 KB |
Output is correct |
45 |
Correct |
11 ms |
1112 KB |
Output is correct |
46 |
Correct |
11 ms |
1108 KB |
Output is correct |
47 |
Correct |
13 ms |
1108 KB |
Output is correct |
48 |
Correct |
12 ms |
1236 KB |
Output is correct |
49 |
Correct |
10 ms |
1028 KB |
Output is correct |
50 |
Correct |
1 ms |
212 KB |
Output is correct |
51 |
Correct |
832 ms |
21700 KB |
Output is correct |
52 |
Correct |
839 ms |
21708 KB |
Output is correct |
53 |
Correct |
836 ms |
21760 KB |
Output is correct |
54 |
Correct |
906 ms |
21700 KB |
Output is correct |
55 |
Correct |
840 ms |
21704 KB |
Output is correct |
56 |
Correct |
874 ms |
21704 KB |
Output is correct |
57 |
Correct |
838 ms |
21808 KB |
Output is correct |
58 |
Correct |
475 ms |
21704 KB |
Output is correct |
59 |
Correct |
473 ms |
21708 KB |
Output is correct |
60 |
Correct |
1 ms |
212 KB |
Output is correct |
61 |
Correct |
831 ms |
21700 KB |
Output is correct |
62 |
Correct |
891 ms |
21776 KB |
Output is correct |
63 |
Correct |
812 ms |
21696 KB |
Output is correct |
64 |
Correct |
803 ms |
21696 KB |
Output is correct |
65 |
Correct |
804 ms |
21732 KB |
Output is correct |
66 |
Correct |
790 ms |
21712 KB |
Output is correct |
67 |
Correct |
790 ms |
21700 KB |
Output is correct |
68 |
Correct |
806 ms |
21692 KB |
Output is correct |
69 |
Correct |
793 ms |
21700 KB |
Output is correct |
70 |
Correct |
1 ms |
212 KB |
Output is correct |