# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
299640 | 2020-09-15T11:20:48 Z | zwliew | Mountains (NOI20_mountains) | C++17 | 1152 ms | 27128 KB |
#include <algorithm> #include <array> #include <bitset> #include <chrono> #include <climits> #include <cmath> #include <cstring> #include <deque> #include <ext/pb_ds/assoc_container.hpp> #include <fstream> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> // #include "bits/stdc++.h" using namespace std; #ifdef LOCAL #include "../../_library/cc/debug.h" #define FILE "test" #else #define debug(...) 0 #define FILE "cowjog" #endif #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> template <class T> using OrderStatisticTree = __gnu_pbds::tree<T, __gnu_pbds::null_type, less<T>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>; int main() { cin.tie(nullptr)->sync_with_stdio(false); if (fopen(FILE ".in", "r")) { freopen(FILE ".in", "r", stdin); freopen(FILE ".out", "w", stdout); } // Iterate through each possible middle mountain, and count the number of // mountains shorter than the middle mountain on both sides. int n; cin >> n; vector<int64_t> h(n); OrderStatisticTree<pair<int64_t, int>> left, right; for (int i = 0; i < n; ++i) { cin >> h[i]; right.insert({h[i], i}); } int64_t ans = 0; for (int i = 0; i < n - 1; ++i) { right.erase(right.lower_bound({h[i], 0})); ans += (int64_t)left.order_of_key({h[i], 0}) * right.order_of_key({h[i], 0}); left.insert({h[i], i}); } cout << ans; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 384 KB | Output is correct |
2 | Correct | 626 ms | 21624 KB | Output is correct |
3 | Correct | 614 ms | 27128 KB | Output is correct |
4 | Correct | 638 ms | 27128 KB | Output is correct |
5 | Correct | 630 ms | 27000 KB | Output is correct |
6 | Correct | 623 ms | 27000 KB | Output is correct |
7 | Correct | 624 ms | 27000 KB | Output is correct |
8 | Correct | 625 ms | 27128 KB | Output is correct |
9 | Correct | 631 ms | 27000 KB | Output is correct |
10 | Correct | 640 ms | 27000 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 416 ms | 21624 KB | Output is correct |
2 | Correct | 420 ms | 21500 KB | Output is correct |
3 | Correct | 395 ms | 21496 KB | Output is correct |
4 | Correct | 396 ms | 21496 KB | Output is correct |
5 | Correct | 395 ms | 21496 KB | Output is correct |
6 | Correct | 390 ms | 21496 KB | Output is correct |
7 | Correct | 429 ms | 21496 KB | Output is correct |
8 | Correct | 568 ms | 21624 KB | Output is correct |
9 | Correct | 593 ms | 21496 KB | Output is correct |
10 | Correct | 1 ms | 384 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 416 ms | 21624 KB | Output is correct |
2 | Correct | 420 ms | 21500 KB | Output is correct |
3 | Correct | 395 ms | 21496 KB | Output is correct |
4 | Correct | 396 ms | 21496 KB | Output is correct |
5 | Correct | 395 ms | 21496 KB | Output is correct |
6 | Correct | 390 ms | 21496 KB | Output is correct |
7 | Correct | 429 ms | 21496 KB | Output is correct |
8 | Correct | 568 ms | 21624 KB | Output is correct |
9 | Correct | 593 ms | 21496 KB | Output is correct |
10 | Correct | 1 ms | 384 KB | Output is correct |
11 | Correct | 802 ms | 21624 KB | Output is correct |
12 | Correct | 779 ms | 21496 KB | Output is correct |
13 | Correct | 788 ms | 21496 KB | Output is correct |
14 | Correct | 785 ms | 21496 KB | Output is correct |
15 | Correct | 806 ms | 21496 KB | Output is correct |
16 | Correct | 791 ms | 21608 KB | Output is correct |
17 | Correct | 791 ms | 21496 KB | Output is correct |
18 | Correct | 597 ms | 21496 KB | Output is correct |
19 | Correct | 577 ms | 21496 KB | Output is correct |
20 | Correct | 1 ms | 384 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 384 KB | Output is correct |
2 | Correct | 1 ms | 384 KB | Output is correct |
3 | Correct | 1 ms | 512 KB | Output is correct |
4 | Correct | 1 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 | 1 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 |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 384 KB | Output is correct |
2 | Correct | 1 ms | 384 KB | Output is correct |
3 | Correct | 1 ms | 512 KB | Output is correct |
4 | Correct | 1 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 | 1 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 | 13 ms | 1280 KB | Output is correct |
12 | Correct | 13 ms | 1280 KB | Output is correct |
13 | Correct | 13 ms | 1280 KB | Output is correct |
14 | Correct | 13 ms | 1152 KB | Output is correct |
15 | Correct | 13 ms | 1280 KB | Output is correct |
16 | Correct | 13 ms | 1280 KB | Output is correct |
17 | Correct | 13 ms | 1280 KB | Output is correct |
18 | Correct | 13 ms | 1280 KB | Output is correct |
19 | Correct | 12 ms | 1024 KB | Output is correct |
20 | Correct | 1 ms | 384 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 416 ms | 21624 KB | Output is correct |
2 | Correct | 420 ms | 21500 KB | Output is correct |
3 | Correct | 395 ms | 21496 KB | Output is correct |
4 | Correct | 396 ms | 21496 KB | Output is correct |
5 | Correct | 395 ms | 21496 KB | Output is correct |
6 | Correct | 390 ms | 21496 KB | Output is correct |
7 | Correct | 429 ms | 21496 KB | Output is correct |
8 | Correct | 568 ms | 21624 KB | Output is correct |
9 | Correct | 593 ms | 21496 KB | Output is correct |
10 | Correct | 1 ms | 384 KB | Output is correct |
11 | Correct | 802 ms | 21624 KB | Output is correct |
12 | Correct | 779 ms | 21496 KB | Output is correct |
13 | Correct | 788 ms | 21496 KB | Output is correct |
14 | Correct | 785 ms | 21496 KB | Output is correct |
15 | Correct | 806 ms | 21496 KB | Output is correct |
16 | Correct | 791 ms | 21608 KB | Output is correct |
17 | Correct | 791 ms | 21496 KB | Output is correct |
18 | Correct | 597 ms | 21496 KB | Output is correct |
19 | Correct | 577 ms | 21496 KB | Output is correct |
20 | Correct | 1 ms | 384 KB | Output is correct |
21 | Correct | 1104 ms | 21496 KB | Output is correct |
22 | Correct | 1096 ms | 21628 KB | Output is correct |
23 | Correct | 1110 ms | 21684 KB | Output is correct |
24 | Correct | 1108 ms | 21500 KB | Output is correct |
25 | Correct | 1120 ms | 21496 KB | Output is correct |
26 | Correct | 1094 ms | 21496 KB | Output is correct |
27 | Correct | 1106 ms | 21496 KB | Output is correct |
28 | Correct | 621 ms | 21496 KB | Output is correct |
29 | Correct | 596 ms | 21496 KB | Output is correct |
30 | Correct | 1 ms | 512 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 384 KB | Output is correct |
2 | Correct | 626 ms | 21624 KB | Output is correct |
3 | Correct | 614 ms | 27128 KB | Output is correct |
4 | Correct | 638 ms | 27128 KB | Output is correct |
5 | Correct | 630 ms | 27000 KB | Output is correct |
6 | Correct | 623 ms | 27000 KB | Output is correct |
7 | Correct | 624 ms | 27000 KB | Output is correct |
8 | Correct | 625 ms | 27128 KB | Output is correct |
9 | Correct | 631 ms | 27000 KB | Output is correct |
10 | Correct | 640 ms | 27000 KB | Output is correct |
11 | Correct | 416 ms | 21624 KB | Output is correct |
12 | Correct | 420 ms | 21500 KB | Output is correct |
13 | Correct | 395 ms | 21496 KB | Output is correct |
14 | Correct | 396 ms | 21496 KB | Output is correct |
15 | Correct | 395 ms | 21496 KB | Output is correct |
16 | Correct | 390 ms | 21496 KB | Output is correct |
17 | Correct | 429 ms | 21496 KB | Output is correct |
18 | Correct | 568 ms | 21624 KB | Output is correct |
19 | Correct | 593 ms | 21496 KB | Output is correct |
20 | Correct | 1 ms | 384 KB | Output is correct |
21 | Correct | 802 ms | 21624 KB | Output is correct |
22 | Correct | 779 ms | 21496 KB | Output is correct |
23 | Correct | 788 ms | 21496 KB | Output is correct |
24 | Correct | 785 ms | 21496 KB | Output is correct |
25 | Correct | 806 ms | 21496 KB | Output is correct |
26 | Correct | 791 ms | 21608 KB | Output is correct |
27 | Correct | 791 ms | 21496 KB | Output is correct |
28 | Correct | 597 ms | 21496 KB | Output is correct |
29 | Correct | 577 ms | 21496 KB | Output is correct |
30 | Correct | 1 ms | 384 KB | Output is correct |
31 | Correct | 1 ms | 384 KB | Output is correct |
32 | Correct | 1 ms | 384 KB | Output is correct |
33 | Correct | 1 ms | 512 KB | Output is correct |
34 | Correct | 1 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 | 1 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 | 13 ms | 1280 KB | Output is correct |
42 | Correct | 13 ms | 1280 KB | Output is correct |
43 | Correct | 13 ms | 1280 KB | Output is correct |
44 | Correct | 13 ms | 1152 KB | Output is correct |
45 | Correct | 13 ms | 1280 KB | Output is correct |
46 | Correct | 13 ms | 1280 KB | Output is correct |
47 | Correct | 13 ms | 1280 KB | Output is correct |
48 | Correct | 13 ms | 1280 KB | Output is correct |
49 | Correct | 12 ms | 1024 KB | Output is correct |
50 | Correct | 1 ms | 384 KB | Output is correct |
51 | Correct | 1104 ms | 21496 KB | Output is correct |
52 | Correct | 1096 ms | 21628 KB | Output is correct |
53 | Correct | 1110 ms | 21684 KB | Output is correct |
54 | Correct | 1108 ms | 21500 KB | Output is correct |
55 | Correct | 1120 ms | 21496 KB | Output is correct |
56 | Correct | 1094 ms | 21496 KB | Output is correct |
57 | Correct | 1106 ms | 21496 KB | Output is correct |
58 | Correct | 621 ms | 21496 KB | Output is correct |
59 | Correct | 596 ms | 21496 KB | Output is correct |
60 | Correct | 1 ms | 512 KB | Output is correct |
61 | Correct | 1104 ms | 27044 KB | Output is correct |
62 | Correct | 1086 ms | 27000 KB | Output is correct |
63 | Correct | 1111 ms | 27096 KB | Output is correct |
64 | Correct | 1106 ms | 27036 KB | Output is correct |
65 | Correct | 1090 ms | 27000 KB | Output is correct |
66 | Correct | 1088 ms | 27000 KB | Output is correct |
67 | Correct | 1101 ms | 27128 KB | Output is correct |
68 | Correct | 1152 ms | 27128 KB | Output is correct |
69 | Correct | 1101 ms | 23288 KB | Output is correct |
70 | Correct | 1 ms | 384 KB | Output is correct |