#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template <class T>
using indexed_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
int main() {
ios::sync_with_stdio(0);
cout.tie(0);
cin.tie(0);
ll n;
cin >> n;
vector<ll> h(n);
for (ll& i : h) {
cin >> i;
}
indexed_set<pair<ll, ll>> l, r;
ll id = 0;
for (ll i : h) {
r.insert({i, id});
id++;
}
ll ans = 0;
for (ll i : h) {
r.erase(r.lower_bound({i, 0}));
ll a = l.order_of_key({i - 1, INT_MAX});
ll b = r.order_of_key({i - 1, INT_MAX});
ans += a * b;
l.insert({i, id});
id++;
}
cout << ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
521 ms |
21348 KB |
Output is correct |
3 |
Correct |
512 ms |
26876 KB |
Output is correct |
4 |
Correct |
528 ms |
26952 KB |
Output is correct |
5 |
Correct |
528 ms |
27048 KB |
Output is correct |
6 |
Correct |
519 ms |
27016 KB |
Output is correct |
7 |
Correct |
490 ms |
27112 KB |
Output is correct |
8 |
Correct |
521 ms |
26928 KB |
Output is correct |
9 |
Correct |
522 ms |
26996 KB |
Output is correct |
10 |
Correct |
523 ms |
27052 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
274 ms |
21400 KB |
Output is correct |
2 |
Correct |
280 ms |
21984 KB |
Output is correct |
3 |
Correct |
277 ms |
22064 KB |
Output is correct |
4 |
Correct |
281 ms |
22100 KB |
Output is correct |
5 |
Correct |
266 ms |
22028 KB |
Output is correct |
6 |
Correct |
279 ms |
22048 KB |
Output is correct |
7 |
Correct |
259 ms |
22100 KB |
Output is correct |
8 |
Correct |
502 ms |
22096 KB |
Output is correct |
9 |
Correct |
498 ms |
22088 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
274 ms |
21400 KB |
Output is correct |
2 |
Correct |
280 ms |
21984 KB |
Output is correct |
3 |
Correct |
277 ms |
22064 KB |
Output is correct |
4 |
Correct |
281 ms |
22100 KB |
Output is correct |
5 |
Correct |
266 ms |
22028 KB |
Output is correct |
6 |
Correct |
279 ms |
22048 KB |
Output is correct |
7 |
Correct |
259 ms |
22100 KB |
Output is correct |
8 |
Correct |
502 ms |
22096 KB |
Output is correct |
9 |
Correct |
498 ms |
22088 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
544 ms |
22176 KB |
Output is correct |
12 |
Correct |
503 ms |
22332 KB |
Output is correct |
13 |
Correct |
487 ms |
22400 KB |
Output is correct |
14 |
Correct |
550 ms |
22316 KB |
Output is correct |
15 |
Correct |
518 ms |
22328 KB |
Output is correct |
16 |
Correct |
513 ms |
22232 KB |
Output is correct |
17 |
Correct |
516 ms |
22328 KB |
Output is correct |
18 |
Correct |
505 ms |
22356 KB |
Output is correct |
19 |
Correct |
483 ms |
22444 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
9 ms |
1116 KB |
Output is correct |
12 |
Correct |
9 ms |
1284 KB |
Output is correct |
13 |
Correct |
9 ms |
1112 KB |
Output is correct |
14 |
Correct |
12 ms |
1116 KB |
Output is correct |
15 |
Correct |
9 ms |
1116 KB |
Output is correct |
16 |
Correct |
10 ms |
1368 KB |
Output is correct |
17 |
Correct |
9 ms |
1116 KB |
Output is correct |
18 |
Correct |
9 ms |
1116 KB |
Output is correct |
19 |
Correct |
9 ms |
1116 KB |
Output is correct |
20 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
274 ms |
21400 KB |
Output is correct |
2 |
Correct |
280 ms |
21984 KB |
Output is correct |
3 |
Correct |
277 ms |
22064 KB |
Output is correct |
4 |
Correct |
281 ms |
22100 KB |
Output is correct |
5 |
Correct |
266 ms |
22028 KB |
Output is correct |
6 |
Correct |
279 ms |
22048 KB |
Output is correct |
7 |
Correct |
259 ms |
22100 KB |
Output is correct |
8 |
Correct |
502 ms |
22096 KB |
Output is correct |
9 |
Correct |
498 ms |
22088 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
544 ms |
22176 KB |
Output is correct |
12 |
Correct |
503 ms |
22332 KB |
Output is correct |
13 |
Correct |
487 ms |
22400 KB |
Output is correct |
14 |
Correct |
550 ms |
22316 KB |
Output is correct |
15 |
Correct |
518 ms |
22328 KB |
Output is correct |
16 |
Correct |
513 ms |
22232 KB |
Output is correct |
17 |
Correct |
516 ms |
22328 KB |
Output is correct |
18 |
Correct |
505 ms |
22356 KB |
Output is correct |
19 |
Correct |
483 ms |
22444 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
606 ms |
23276 KB |
Output is correct |
22 |
Correct |
579 ms |
23112 KB |
Output is correct |
23 |
Correct |
670 ms |
23204 KB |
Output is correct |
24 |
Correct |
626 ms |
23120 KB |
Output is correct |
25 |
Correct |
646 ms |
23120 KB |
Output is correct |
26 |
Correct |
612 ms |
23120 KB |
Output is correct |
27 |
Correct |
559 ms |
23116 KB |
Output is correct |
28 |
Correct |
506 ms |
23072 KB |
Output is correct |
29 |
Correct |
508 ms |
23384 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
521 ms |
21348 KB |
Output is correct |
3 |
Correct |
512 ms |
26876 KB |
Output is correct |
4 |
Correct |
528 ms |
26952 KB |
Output is correct |
5 |
Correct |
528 ms |
27048 KB |
Output is correct |
6 |
Correct |
519 ms |
27016 KB |
Output is correct |
7 |
Correct |
490 ms |
27112 KB |
Output is correct |
8 |
Correct |
521 ms |
26928 KB |
Output is correct |
9 |
Correct |
522 ms |
26996 KB |
Output is correct |
10 |
Correct |
523 ms |
27052 KB |
Output is correct |
11 |
Correct |
274 ms |
21400 KB |
Output is correct |
12 |
Correct |
280 ms |
21984 KB |
Output is correct |
13 |
Correct |
277 ms |
22064 KB |
Output is correct |
14 |
Correct |
281 ms |
22100 KB |
Output is correct |
15 |
Correct |
266 ms |
22028 KB |
Output is correct |
16 |
Correct |
279 ms |
22048 KB |
Output is correct |
17 |
Correct |
259 ms |
22100 KB |
Output is correct |
18 |
Correct |
502 ms |
22096 KB |
Output is correct |
19 |
Correct |
498 ms |
22088 KB |
Output is correct |
20 |
Correct |
0 ms |
344 KB |
Output is correct |
21 |
Correct |
544 ms |
22176 KB |
Output is correct |
22 |
Correct |
503 ms |
22332 KB |
Output is correct |
23 |
Correct |
487 ms |
22400 KB |
Output is correct |
24 |
Correct |
550 ms |
22316 KB |
Output is correct |
25 |
Correct |
518 ms |
22328 KB |
Output is correct |
26 |
Correct |
513 ms |
22232 KB |
Output is correct |
27 |
Correct |
516 ms |
22328 KB |
Output is correct |
28 |
Correct |
505 ms |
22356 KB |
Output is correct |
29 |
Correct |
483 ms |
22444 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Correct |
1 ms |
344 KB |
Output is correct |
32 |
Correct |
1 ms |
344 KB |
Output is correct |
33 |
Correct |
1 ms |
344 KB |
Output is correct |
34 |
Correct |
1 ms |
348 KB |
Output is correct |
35 |
Correct |
1 ms |
348 KB |
Output is correct |
36 |
Correct |
1 ms |
344 KB |
Output is correct |
37 |
Correct |
1 ms |
344 KB |
Output is correct |
38 |
Correct |
1 ms |
344 KB |
Output is correct |
39 |
Correct |
1 ms |
348 KB |
Output is correct |
40 |
Correct |
0 ms |
348 KB |
Output is correct |
41 |
Correct |
9 ms |
1116 KB |
Output is correct |
42 |
Correct |
9 ms |
1284 KB |
Output is correct |
43 |
Correct |
9 ms |
1112 KB |
Output is correct |
44 |
Correct |
12 ms |
1116 KB |
Output is correct |
45 |
Correct |
9 ms |
1116 KB |
Output is correct |
46 |
Correct |
10 ms |
1368 KB |
Output is correct |
47 |
Correct |
9 ms |
1116 KB |
Output is correct |
48 |
Correct |
9 ms |
1116 KB |
Output is correct |
49 |
Correct |
9 ms |
1116 KB |
Output is correct |
50 |
Correct |
0 ms |
344 KB |
Output is correct |
51 |
Correct |
606 ms |
23276 KB |
Output is correct |
52 |
Correct |
579 ms |
23112 KB |
Output is correct |
53 |
Correct |
670 ms |
23204 KB |
Output is correct |
54 |
Correct |
626 ms |
23120 KB |
Output is correct |
55 |
Correct |
646 ms |
23120 KB |
Output is correct |
56 |
Correct |
612 ms |
23120 KB |
Output is correct |
57 |
Correct |
559 ms |
23116 KB |
Output is correct |
58 |
Correct |
506 ms |
23072 KB |
Output is correct |
59 |
Correct |
508 ms |
23384 KB |
Output is correct |
60 |
Correct |
0 ms |
348 KB |
Output is correct |
61 |
Correct |
695 ms |
26960 KB |
Output is correct |
62 |
Correct |
605 ms |
26960 KB |
Output is correct |
63 |
Correct |
649 ms |
27060 KB |
Output is correct |
64 |
Correct |
586 ms |
26960 KB |
Output is correct |
65 |
Correct |
601 ms |
26964 KB |
Output is correct |
66 |
Correct |
596 ms |
26992 KB |
Output is correct |
67 |
Correct |
607 ms |
27288 KB |
Output is correct |
68 |
Correct |
631 ms |
27132 KB |
Output is correct |
69 |
Correct |
569 ms |
23328 KB |
Output is correct |
70 |
Correct |
0 ms |
348 KB |
Output is correct |