#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds;
#define int long long
typedef tree<pair<int,int>, null_type, less<pair<int,int> >, rb_tree_tag, tree_order_statistics_node_update> ost;
int32_t main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
int a[n+1];
for(int i=1; i<=n; i++) cin >> a[i];
ost left, right;
for(int i=3; i<=n; i++) right.insert({a[i],i});
left.insert({a[1],1});
int ans = left.order_of_key({a[2],0}) * right.order_of_key({a[2],0});
for(int i=3; i<n; i++) {
left.insert({a[i-1],i-1});
right.erase({a[i],i});
ans += left.order_of_key({a[i],0}) * right.order_of_key({a[i],0});
}
cout << ans << "\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
504 ms |
21964 KB |
Output is correct |
3 |
Correct |
502 ms |
22072 KB |
Output is correct |
4 |
Correct |
515 ms |
22068 KB |
Output is correct |
5 |
Correct |
501 ms |
22040 KB |
Output is correct |
6 |
Correct |
509 ms |
22168 KB |
Output is correct |
7 |
Correct |
505 ms |
22092 KB |
Output is correct |
8 |
Correct |
506 ms |
21996 KB |
Output is correct |
9 |
Correct |
511 ms |
21944 KB |
Output is correct |
10 |
Correct |
512 ms |
22032 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
257 ms |
21848 KB |
Output is correct |
2 |
Correct |
269 ms |
21892 KB |
Output is correct |
3 |
Correct |
256 ms |
22024 KB |
Output is correct |
4 |
Correct |
251 ms |
21936 KB |
Output is correct |
5 |
Correct |
262 ms |
21964 KB |
Output is correct |
6 |
Correct |
260 ms |
22024 KB |
Output is correct |
7 |
Correct |
255 ms |
22016 KB |
Output is correct |
8 |
Correct |
508 ms |
22032 KB |
Output is correct |
9 |
Correct |
499 ms |
21952 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
257 ms |
21848 KB |
Output is correct |
2 |
Correct |
269 ms |
21892 KB |
Output is correct |
3 |
Correct |
256 ms |
22024 KB |
Output is correct |
4 |
Correct |
251 ms |
21936 KB |
Output is correct |
5 |
Correct |
262 ms |
21964 KB |
Output is correct |
6 |
Correct |
260 ms |
22024 KB |
Output is correct |
7 |
Correct |
255 ms |
22016 KB |
Output is correct |
8 |
Correct |
508 ms |
22032 KB |
Output is correct |
9 |
Correct |
499 ms |
21952 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
444 ms |
22280 KB |
Output is correct |
12 |
Correct |
488 ms |
22280 KB |
Output is correct |
13 |
Correct |
483 ms |
22284 KB |
Output is correct |
14 |
Correct |
477 ms |
22288 KB |
Output is correct |
15 |
Correct |
481 ms |
22284 KB |
Output is correct |
16 |
Correct |
487 ms |
22284 KB |
Output is correct |
17 |
Correct |
474 ms |
22280 KB |
Output is correct |
18 |
Correct |
483 ms |
22184 KB |
Output is correct |
19 |
Correct |
479 ms |
22332 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
328 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 |
324 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 |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
328 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 |
324 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 |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
9 ms |
1108 KB |
Output is correct |
12 |
Correct |
12 ms |
1108 KB |
Output is correct |
13 |
Correct |
9 ms |
1208 KB |
Output is correct |
14 |
Correct |
10 ms |
1208 KB |
Output is correct |
15 |
Correct |
9 ms |
1200 KB |
Output is correct |
16 |
Correct |
9 ms |
1108 KB |
Output is correct |
17 |
Correct |
9 ms |
1108 KB |
Output is correct |
18 |
Correct |
9 ms |
1108 KB |
Output is correct |
19 |
Correct |
8 ms |
980 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
257 ms |
21848 KB |
Output is correct |
2 |
Correct |
269 ms |
21892 KB |
Output is correct |
3 |
Correct |
256 ms |
22024 KB |
Output is correct |
4 |
Correct |
251 ms |
21936 KB |
Output is correct |
5 |
Correct |
262 ms |
21964 KB |
Output is correct |
6 |
Correct |
260 ms |
22024 KB |
Output is correct |
7 |
Correct |
255 ms |
22016 KB |
Output is correct |
8 |
Correct |
508 ms |
22032 KB |
Output is correct |
9 |
Correct |
499 ms |
21952 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
444 ms |
22280 KB |
Output is correct |
12 |
Correct |
488 ms |
22280 KB |
Output is correct |
13 |
Correct |
483 ms |
22284 KB |
Output is correct |
14 |
Correct |
477 ms |
22288 KB |
Output is correct |
15 |
Correct |
481 ms |
22284 KB |
Output is correct |
16 |
Correct |
487 ms |
22284 KB |
Output is correct |
17 |
Correct |
474 ms |
22280 KB |
Output is correct |
18 |
Correct |
483 ms |
22184 KB |
Output is correct |
19 |
Correct |
479 ms |
22332 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
722 ms |
23160 KB |
Output is correct |
22 |
Correct |
689 ms |
23164 KB |
Output is correct |
23 |
Correct |
631 ms |
23168 KB |
Output is correct |
24 |
Correct |
605 ms |
23116 KB |
Output is correct |
25 |
Correct |
607 ms |
23160 KB |
Output is correct |
26 |
Correct |
622 ms |
23116 KB |
Output is correct |
27 |
Correct |
619 ms |
23164 KB |
Output is correct |
28 |
Correct |
500 ms |
23168 KB |
Output is correct |
29 |
Correct |
503 ms |
23212 KB |
Output is correct |
30 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
504 ms |
21964 KB |
Output is correct |
3 |
Correct |
502 ms |
22072 KB |
Output is correct |
4 |
Correct |
515 ms |
22068 KB |
Output is correct |
5 |
Correct |
501 ms |
22040 KB |
Output is correct |
6 |
Correct |
509 ms |
22168 KB |
Output is correct |
7 |
Correct |
505 ms |
22092 KB |
Output is correct |
8 |
Correct |
506 ms |
21996 KB |
Output is correct |
9 |
Correct |
511 ms |
21944 KB |
Output is correct |
10 |
Correct |
512 ms |
22032 KB |
Output is correct |
11 |
Correct |
257 ms |
21848 KB |
Output is correct |
12 |
Correct |
269 ms |
21892 KB |
Output is correct |
13 |
Correct |
256 ms |
22024 KB |
Output is correct |
14 |
Correct |
251 ms |
21936 KB |
Output is correct |
15 |
Correct |
262 ms |
21964 KB |
Output is correct |
16 |
Correct |
260 ms |
22024 KB |
Output is correct |
17 |
Correct |
255 ms |
22016 KB |
Output is correct |
18 |
Correct |
508 ms |
22032 KB |
Output is correct |
19 |
Correct |
499 ms |
21952 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
444 ms |
22280 KB |
Output is correct |
22 |
Correct |
488 ms |
22280 KB |
Output is correct |
23 |
Correct |
483 ms |
22284 KB |
Output is correct |
24 |
Correct |
477 ms |
22288 KB |
Output is correct |
25 |
Correct |
481 ms |
22284 KB |
Output is correct |
26 |
Correct |
487 ms |
22284 KB |
Output is correct |
27 |
Correct |
474 ms |
22280 KB |
Output is correct |
28 |
Correct |
483 ms |
22184 KB |
Output is correct |
29 |
Correct |
479 ms |
22332 KB |
Output is correct |
30 |
Correct |
1 ms |
212 KB |
Output is correct |
31 |
Correct |
1 ms |
332 KB |
Output is correct |
32 |
Correct |
1 ms |
328 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 |
324 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 |
0 ms |
212 KB |
Output is correct |
41 |
Correct |
9 ms |
1108 KB |
Output is correct |
42 |
Correct |
12 ms |
1108 KB |
Output is correct |
43 |
Correct |
9 ms |
1208 KB |
Output is correct |
44 |
Correct |
10 ms |
1208 KB |
Output is correct |
45 |
Correct |
9 ms |
1200 KB |
Output is correct |
46 |
Correct |
9 ms |
1108 KB |
Output is correct |
47 |
Correct |
9 ms |
1108 KB |
Output is correct |
48 |
Correct |
9 ms |
1108 KB |
Output is correct |
49 |
Correct |
8 ms |
980 KB |
Output is correct |
50 |
Correct |
1 ms |
212 KB |
Output is correct |
51 |
Correct |
722 ms |
23160 KB |
Output is correct |
52 |
Correct |
689 ms |
23164 KB |
Output is correct |
53 |
Correct |
631 ms |
23168 KB |
Output is correct |
54 |
Correct |
605 ms |
23116 KB |
Output is correct |
55 |
Correct |
607 ms |
23160 KB |
Output is correct |
56 |
Correct |
622 ms |
23116 KB |
Output is correct |
57 |
Correct |
619 ms |
23164 KB |
Output is correct |
58 |
Correct |
500 ms |
23168 KB |
Output is correct |
59 |
Correct |
503 ms |
23212 KB |
Output is correct |
60 |
Correct |
0 ms |
212 KB |
Output is correct |
61 |
Correct |
589 ms |
26972 KB |
Output is correct |
62 |
Correct |
609 ms |
26972 KB |
Output is correct |
63 |
Correct |
611 ms |
26972 KB |
Output is correct |
64 |
Correct |
628 ms |
27080 KB |
Output is correct |
65 |
Correct |
627 ms |
26972 KB |
Output is correct |
66 |
Correct |
598 ms |
26988 KB |
Output is correct |
67 |
Correct |
595 ms |
26968 KB |
Output is correct |
68 |
Correct |
608 ms |
27020 KB |
Output is correct |
69 |
Correct |
596 ms |
23272 KB |
Output is correct |
70 |
Correct |
0 ms |
212 KB |
Output is correct |