# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
585377 | 2022-06-28T18:39:24 Z | Kanaifu | Mountains (NOI20_mountains) | C++14 | 123 ms | 14924 KB |
#include <bits/stdc++.h> using namespace std; #define pb push_back #define fr first #define sc second int tree[300001]; int n; int sum(int ind) { int zbir = 0; while (ind > 0) { zbir += tree[ind]; ind = (ind)&(ind-1); } return zbir; } void update(int ind) { while (ind <= n) { tree[ind]++; ind += (ind - (ind & (ind-1))); } } long long query(int left, int right) { return (sum(right) - sum(left - 1)); } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long brojac = 0; memset(tree, 0, sizeof(tree)); vector <int> reset; vector <pair<long long, int>> order; cin>>n; for (int i=1; i<=n; i++) { long long height; cin>>height; order.pb({height, i}); } sort(order.begin(), order.end()); long long last = -1; for (int i=0; i<order.size(); i++) { if (order[i].fr != last) { for (int el : reset) { update(el); } reset.clear(); } brojac += (query(1, order[i].sc-1))*(query(order[i].sc+1, n)); reset.pb(order[i].sc); last = order[i].fr; } cout<<brojac; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 1492 KB | Output is correct |
2 | Correct | 74 ms | 14740 KB | Output is correct |
3 | Correct | 72 ms | 14696 KB | Output is correct |
4 | Correct | 72 ms | 14728 KB | Output is correct |
5 | Correct | 70 ms | 14756 KB | Output is correct |
6 | Correct | 88 ms | 14780 KB | Output is correct |
7 | Correct | 75 ms | 14700 KB | Output is correct |
8 | Correct | 69 ms | 14812 KB | Output is correct |
9 | Correct | 74 ms | 14888 KB | Output is correct |
10 | Correct | 78 ms | 14924 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 62 ms | 10316 KB | Output is correct |
2 | Correct | 61 ms | 10352 KB | Output is correct |
3 | Correct | 58 ms | 10396 KB | Output is correct |
4 | Correct | 54 ms | 10340 KB | Output is correct |
5 | Correct | 58 ms | 10316 KB | Output is correct |
6 | Correct | 56 ms | 10428 KB | Output is correct |
7 | Correct | 67 ms | 10408 KB | Output is correct |
8 | Correct | 42 ms | 10372 KB | Output is correct |
9 | Correct | 40 ms | 10396 KB | Output is correct |
10 | Correct | 1 ms | 1492 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 62 ms | 10316 KB | Output is correct |
2 | Correct | 61 ms | 10352 KB | Output is correct |
3 | Correct | 58 ms | 10396 KB | Output is correct |
4 | Correct | 54 ms | 10340 KB | Output is correct |
5 | Correct | 58 ms | 10316 KB | Output is correct |
6 | Correct | 56 ms | 10428 KB | Output is correct |
7 | Correct | 67 ms | 10408 KB | Output is correct |
8 | Correct | 42 ms | 10372 KB | Output is correct |
9 | Correct | 40 ms | 10396 KB | Output is correct |
10 | Correct | 1 ms | 1492 KB | Output is correct |
11 | Correct | 70 ms | 10652 KB | Output is correct |
12 | Correct | 73 ms | 10684 KB | Output is correct |
13 | Correct | 70 ms | 10648 KB | Output is correct |
14 | Correct | 67 ms | 10604 KB | Output is correct |
15 | Correct | 66 ms | 10708 KB | Output is correct |
16 | Correct | 68 ms | 10640 KB | Output is correct |
17 | Correct | 68 ms | 10684 KB | Output is correct |
18 | Correct | 53 ms | 10580 KB | Output is correct |
19 | Correct | 45 ms | 10696 KB | Output is correct |
20 | Correct | 1 ms | 1500 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 1492 KB | Output is correct |
2 | Correct | 1 ms | 1492 KB | Output is correct |
3 | Correct | 1 ms | 1500 KB | Output is correct |
4 | Correct | 1 ms | 1492 KB | Output is correct |
5 | Correct | 1 ms | 1492 KB | Output is correct |
6 | Correct | 1 ms | 1492 KB | Output is correct |
7 | Correct | 1 ms | 1492 KB | Output is correct |
8 | Correct | 1 ms | 1492 KB | Output is correct |
9 | Correct | 2 ms | 1492 KB | Output is correct |
10 | Correct | 1 ms | 1492 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 1492 KB | Output is correct |
2 | Correct | 1 ms | 1492 KB | Output is correct |
3 | Correct | 1 ms | 1500 KB | Output is correct |
4 | Correct | 1 ms | 1492 KB | Output is correct |
5 | Correct | 1 ms | 1492 KB | Output is correct |
6 | Correct | 1 ms | 1492 KB | Output is correct |
7 | Correct | 1 ms | 1492 KB | Output is correct |
8 | Correct | 1 ms | 1492 KB | Output is correct |
9 | Correct | 2 ms | 1492 KB | Output is correct |
10 | Correct | 1 ms | 1492 KB | Output is correct |
11 | Correct | 5 ms | 2004 KB | Output is correct |
12 | Correct | 4 ms | 2004 KB | Output is correct |
13 | Correct | 6 ms | 2028 KB | Output is correct |
14 | Correct | 6 ms | 2020 KB | Output is correct |
15 | Correct | 4 ms | 2020 KB | Output is correct |
16 | Correct | 5 ms | 2004 KB | Output is correct |
17 | Correct | 4 ms | 2004 KB | Output is correct |
18 | Correct | 4 ms | 2016 KB | Output is correct |
19 | Correct | 3 ms | 1876 KB | Output is correct |
20 | Correct | 1 ms | 1492 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 62 ms | 10316 KB | Output is correct |
2 | Correct | 61 ms | 10352 KB | Output is correct |
3 | Correct | 58 ms | 10396 KB | Output is correct |
4 | Correct | 54 ms | 10340 KB | Output is correct |
5 | Correct | 58 ms | 10316 KB | Output is correct |
6 | Correct | 56 ms | 10428 KB | Output is correct |
7 | Correct | 67 ms | 10408 KB | Output is correct |
8 | Correct | 42 ms | 10372 KB | Output is correct |
9 | Correct | 40 ms | 10396 KB | Output is correct |
10 | Correct | 1 ms | 1492 KB | Output is correct |
11 | Correct | 70 ms | 10652 KB | Output is correct |
12 | Correct | 73 ms | 10684 KB | Output is correct |
13 | Correct | 70 ms | 10648 KB | Output is correct |
14 | Correct | 67 ms | 10604 KB | Output is correct |
15 | Correct | 66 ms | 10708 KB | Output is correct |
16 | Correct | 68 ms | 10640 KB | Output is correct |
17 | Correct | 68 ms | 10684 KB | Output is correct |
18 | Correct | 53 ms | 10580 KB | Output is correct |
19 | Correct | 45 ms | 10696 KB | Output is correct |
20 | Correct | 1 ms | 1500 KB | Output is correct |
21 | Correct | 77 ms | 11468 KB | Output is correct |
22 | Correct | 73 ms | 11428 KB | Output is correct |
23 | Correct | 79 ms | 11416 KB | Output is correct |
24 | Correct | 75 ms | 11456 KB | Output is correct |
25 | Correct | 78 ms | 11456 KB | Output is correct |
26 | Correct | 78 ms | 11372 KB | Output is correct |
27 | Correct | 80 ms | 11416 KB | Output is correct |
28 | Correct | 63 ms | 11464 KB | Output is correct |
29 | Correct | 56 ms | 11420 KB | Output is correct |
30 | Correct | 1 ms | 1492 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 1492 KB | Output is correct |
2 | Correct | 74 ms | 14740 KB | Output is correct |
3 | Correct | 72 ms | 14696 KB | Output is correct |
4 | Correct | 72 ms | 14728 KB | Output is correct |
5 | Correct | 70 ms | 14756 KB | Output is correct |
6 | Correct | 88 ms | 14780 KB | Output is correct |
7 | Correct | 75 ms | 14700 KB | Output is correct |
8 | Correct | 69 ms | 14812 KB | Output is correct |
9 | Correct | 74 ms | 14888 KB | Output is correct |
10 | Correct | 78 ms | 14924 KB | Output is correct |
11 | Correct | 62 ms | 10316 KB | Output is correct |
12 | Correct | 61 ms | 10352 KB | Output is correct |
13 | Correct | 58 ms | 10396 KB | Output is correct |
14 | Correct | 54 ms | 10340 KB | Output is correct |
15 | Correct | 58 ms | 10316 KB | Output is correct |
16 | Correct | 56 ms | 10428 KB | Output is correct |
17 | Correct | 67 ms | 10408 KB | Output is correct |
18 | Correct | 42 ms | 10372 KB | Output is correct |
19 | Correct | 40 ms | 10396 KB | Output is correct |
20 | Correct | 1 ms | 1492 KB | Output is correct |
21 | Correct | 70 ms | 10652 KB | Output is correct |
22 | Correct | 73 ms | 10684 KB | Output is correct |
23 | Correct | 70 ms | 10648 KB | Output is correct |
24 | Correct | 67 ms | 10604 KB | Output is correct |
25 | Correct | 66 ms | 10708 KB | Output is correct |
26 | Correct | 68 ms | 10640 KB | Output is correct |
27 | Correct | 68 ms | 10684 KB | Output is correct |
28 | Correct | 53 ms | 10580 KB | Output is correct |
29 | Correct | 45 ms | 10696 KB | Output is correct |
30 | Correct | 1 ms | 1500 KB | Output is correct |
31 | Correct | 1 ms | 1492 KB | Output is correct |
32 | Correct | 1 ms | 1492 KB | Output is correct |
33 | Correct | 1 ms | 1500 KB | Output is correct |
34 | Correct | 1 ms | 1492 KB | Output is correct |
35 | Correct | 1 ms | 1492 KB | Output is correct |
36 | Correct | 1 ms | 1492 KB | Output is correct |
37 | Correct | 1 ms | 1492 KB | Output is correct |
38 | Correct | 1 ms | 1492 KB | Output is correct |
39 | Correct | 2 ms | 1492 KB | Output is correct |
40 | Correct | 1 ms | 1492 KB | Output is correct |
41 | Correct | 5 ms | 2004 KB | Output is correct |
42 | Correct | 4 ms | 2004 KB | Output is correct |
43 | Correct | 6 ms | 2028 KB | Output is correct |
44 | Correct | 6 ms | 2020 KB | Output is correct |
45 | Correct | 4 ms | 2020 KB | Output is correct |
46 | Correct | 5 ms | 2004 KB | Output is correct |
47 | Correct | 4 ms | 2004 KB | Output is correct |
48 | Correct | 4 ms | 2016 KB | Output is correct |
49 | Correct | 3 ms | 1876 KB | Output is correct |
50 | Correct | 1 ms | 1492 KB | Output is correct |
51 | Correct | 77 ms | 11468 KB | Output is correct |
52 | Correct | 73 ms | 11428 KB | Output is correct |
53 | Correct | 79 ms | 11416 KB | Output is correct |
54 | Correct | 75 ms | 11456 KB | Output is correct |
55 | Correct | 78 ms | 11456 KB | Output is correct |
56 | Correct | 78 ms | 11372 KB | Output is correct |
57 | Correct | 80 ms | 11416 KB | Output is correct |
58 | Correct | 63 ms | 11464 KB | Output is correct |
59 | Correct | 56 ms | 11420 KB | Output is correct |
60 | Correct | 1 ms | 1492 KB | Output is correct |
61 | Correct | 108 ms | 14720 KB | Output is correct |
62 | Correct | 107 ms | 14776 KB | Output is correct |
63 | Correct | 116 ms | 14692 KB | Output is correct |
64 | Correct | 110 ms | 14736 KB | Output is correct |
65 | Correct | 106 ms | 14780 KB | Output is correct |
66 | Correct | 111 ms | 14756 KB | Output is correct |
67 | Correct | 121 ms | 14792 KB | Output is correct |
68 | Correct | 123 ms | 14904 KB | Output is correct |
69 | Correct | 76 ms | 11616 KB | Output is correct |
70 | Correct | 1 ms | 1496 KB | Output is correct |