#include <bits/stdc++.h>
#define int long long
using namespace std;
const int O = 3e5 + 5;
int n, a[O], tree[O * 4];
pair <int, int> b[O];
void Update(int id, int l, int r, int u, int x){
if (l > u || r < u) return;
if (l == r){
tree[id] = x;
return;
}
int mid = (l + r) / 2;
Update(id << 1, l, mid, u, x);
Update(id << 1 | 1, mid + 1, r, u, x);
tree[id] = tree[id << 1] + tree[id << 1 | 1];
}
int Get(int id, int l, int r, int u, int v){
if (l > v || r < u) return 0;
if (u <= l && r <= v) return tree[id];
int mid = (l + r) / 2;
return Get(id << 1, l, mid, u, v) + Get(id << 1 | 1, mid + 1, r, u, v);
}
main(){
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
cin >> n;
for (int i = 1; i <= n; ++ i){
cin >> b[i].first; b[i].second = i;
}
int res = 0;
sort(b + 1, b + n + 1);
for (int i = 1; i <= n; ++ i){
int j = i;
while (j < n && b[j + 1].first == b[i].first) j += 1;
for (int z = i; z <= j; ++ z){
int l = Get(1, 1, n, 1, b[z].second);
int r = Get(1, 1, n, b[z].second, n);
res += r * l;
}
for (int z = i; z <= j; ++ z){
Update(1, 1, n, b[z].second, 1);
}
i = j;
}
cout << res;
}
Compilation message
Mountains.cpp:30:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
30 | main(){
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Output is correct |
2 |
Correct |
183 ms |
18736 KB |
Output is correct |
3 |
Correct |
161 ms |
18724 KB |
Output is correct |
4 |
Correct |
170 ms |
18648 KB |
Output is correct |
5 |
Correct |
162 ms |
18760 KB |
Output is correct |
6 |
Correct |
170 ms |
18760 KB |
Output is correct |
7 |
Correct |
172 ms |
18712 KB |
Output is correct |
8 |
Correct |
161 ms |
18760 KB |
Output is correct |
9 |
Correct |
179 ms |
18764 KB |
Output is correct |
10 |
Correct |
184 ms |
18820 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
150 ms |
13728 KB |
Output is correct |
2 |
Correct |
151 ms |
13768 KB |
Output is correct |
3 |
Correct |
152 ms |
13804 KB |
Output is correct |
4 |
Correct |
160 ms |
13804 KB |
Output is correct |
5 |
Correct |
158 ms |
13804 KB |
Output is correct |
6 |
Correct |
165 ms |
13768 KB |
Output is correct |
7 |
Correct |
152 ms |
13772 KB |
Output is correct |
8 |
Correct |
136 ms |
13768 KB |
Output is correct |
9 |
Correct |
132 ms |
13800 KB |
Output is correct |
10 |
Correct |
0 ms |
336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
150 ms |
13728 KB |
Output is correct |
2 |
Correct |
151 ms |
13768 KB |
Output is correct |
3 |
Correct |
152 ms |
13804 KB |
Output is correct |
4 |
Correct |
160 ms |
13804 KB |
Output is correct |
5 |
Correct |
158 ms |
13804 KB |
Output is correct |
6 |
Correct |
165 ms |
13768 KB |
Output is correct |
7 |
Correct |
152 ms |
13772 KB |
Output is correct |
8 |
Correct |
136 ms |
13768 KB |
Output is correct |
9 |
Correct |
132 ms |
13800 KB |
Output is correct |
10 |
Correct |
0 ms |
336 KB |
Output is correct |
11 |
Correct |
194 ms |
14064 KB |
Output is correct |
12 |
Correct |
203 ms |
14164 KB |
Output is correct |
13 |
Correct |
190 ms |
14060 KB |
Output is correct |
14 |
Correct |
186 ms |
14068 KB |
Output is correct |
15 |
Correct |
191 ms |
14024 KB |
Output is correct |
16 |
Correct |
199 ms |
14084 KB |
Output is correct |
17 |
Correct |
247 ms |
14024 KB |
Output is correct |
18 |
Correct |
129 ms |
14068 KB |
Output is correct |
19 |
Correct |
143 ms |
14072 KB |
Output is correct |
20 |
Correct |
0 ms |
208 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
0 ms |
336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
0 ms |
336 KB |
Output is correct |
11 |
Correct |
6 ms |
848 KB |
Output is correct |
12 |
Correct |
6 ms |
844 KB |
Output is correct |
13 |
Correct |
6 ms |
848 KB |
Output is correct |
14 |
Correct |
9 ms |
856 KB |
Output is correct |
15 |
Correct |
6 ms |
848 KB |
Output is correct |
16 |
Correct |
6 ms |
844 KB |
Output is correct |
17 |
Correct |
7 ms |
848 KB |
Output is correct |
18 |
Correct |
7 ms |
936 KB |
Output is correct |
19 |
Correct |
5 ms |
720 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
150 ms |
13728 KB |
Output is correct |
2 |
Correct |
151 ms |
13768 KB |
Output is correct |
3 |
Correct |
152 ms |
13804 KB |
Output is correct |
4 |
Correct |
160 ms |
13804 KB |
Output is correct |
5 |
Correct |
158 ms |
13804 KB |
Output is correct |
6 |
Correct |
165 ms |
13768 KB |
Output is correct |
7 |
Correct |
152 ms |
13772 KB |
Output is correct |
8 |
Correct |
136 ms |
13768 KB |
Output is correct |
9 |
Correct |
132 ms |
13800 KB |
Output is correct |
10 |
Correct |
0 ms |
336 KB |
Output is correct |
11 |
Correct |
194 ms |
14064 KB |
Output is correct |
12 |
Correct |
203 ms |
14164 KB |
Output is correct |
13 |
Correct |
190 ms |
14060 KB |
Output is correct |
14 |
Correct |
186 ms |
14068 KB |
Output is correct |
15 |
Correct |
191 ms |
14024 KB |
Output is correct |
16 |
Correct |
199 ms |
14084 KB |
Output is correct |
17 |
Correct |
247 ms |
14024 KB |
Output is correct |
18 |
Correct |
129 ms |
14068 KB |
Output is correct |
19 |
Correct |
143 ms |
14072 KB |
Output is correct |
20 |
Correct |
0 ms |
208 KB |
Output is correct |
21 |
Correct |
219 ms |
14944 KB |
Output is correct |
22 |
Correct |
237 ms |
14940 KB |
Output is correct |
23 |
Correct |
223 ms |
15000 KB |
Output is correct |
24 |
Correct |
217 ms |
14920 KB |
Output is correct |
25 |
Correct |
212 ms |
14920 KB |
Output is correct |
26 |
Correct |
234 ms |
14992 KB |
Output is correct |
27 |
Correct |
238 ms |
14944 KB |
Output is correct |
28 |
Correct |
145 ms |
14936 KB |
Output is correct |
29 |
Correct |
147 ms |
15008 KB |
Output is correct |
30 |
Correct |
0 ms |
336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Output is correct |
2 |
Correct |
183 ms |
18736 KB |
Output is correct |
3 |
Correct |
161 ms |
18724 KB |
Output is correct |
4 |
Correct |
170 ms |
18648 KB |
Output is correct |
5 |
Correct |
162 ms |
18760 KB |
Output is correct |
6 |
Correct |
170 ms |
18760 KB |
Output is correct |
7 |
Correct |
172 ms |
18712 KB |
Output is correct |
8 |
Correct |
161 ms |
18760 KB |
Output is correct |
9 |
Correct |
179 ms |
18764 KB |
Output is correct |
10 |
Correct |
184 ms |
18820 KB |
Output is correct |
11 |
Correct |
150 ms |
13728 KB |
Output is correct |
12 |
Correct |
151 ms |
13768 KB |
Output is correct |
13 |
Correct |
152 ms |
13804 KB |
Output is correct |
14 |
Correct |
160 ms |
13804 KB |
Output is correct |
15 |
Correct |
158 ms |
13804 KB |
Output is correct |
16 |
Correct |
165 ms |
13768 KB |
Output is correct |
17 |
Correct |
152 ms |
13772 KB |
Output is correct |
18 |
Correct |
136 ms |
13768 KB |
Output is correct |
19 |
Correct |
132 ms |
13800 KB |
Output is correct |
20 |
Correct |
0 ms |
336 KB |
Output is correct |
21 |
Correct |
194 ms |
14064 KB |
Output is correct |
22 |
Correct |
203 ms |
14164 KB |
Output is correct |
23 |
Correct |
190 ms |
14060 KB |
Output is correct |
24 |
Correct |
186 ms |
14068 KB |
Output is correct |
25 |
Correct |
191 ms |
14024 KB |
Output is correct |
26 |
Correct |
199 ms |
14084 KB |
Output is correct |
27 |
Correct |
247 ms |
14024 KB |
Output is correct |
28 |
Correct |
129 ms |
14068 KB |
Output is correct |
29 |
Correct |
143 ms |
14072 KB |
Output is correct |
30 |
Correct |
0 ms |
208 KB |
Output is correct |
31 |
Correct |
1 ms |
336 KB |
Output is correct |
32 |
Correct |
1 ms |
332 KB |
Output is correct |
33 |
Correct |
1 ms |
336 KB |
Output is correct |
34 |
Correct |
1 ms |
336 KB |
Output is correct |
35 |
Correct |
1 ms |
336 KB |
Output is correct |
36 |
Correct |
1 ms |
336 KB |
Output is correct |
37 |
Correct |
1 ms |
336 KB |
Output is correct |
38 |
Correct |
1 ms |
336 KB |
Output is correct |
39 |
Correct |
1 ms |
336 KB |
Output is correct |
40 |
Correct |
0 ms |
336 KB |
Output is correct |
41 |
Correct |
6 ms |
848 KB |
Output is correct |
42 |
Correct |
6 ms |
844 KB |
Output is correct |
43 |
Correct |
6 ms |
848 KB |
Output is correct |
44 |
Correct |
9 ms |
856 KB |
Output is correct |
45 |
Correct |
6 ms |
848 KB |
Output is correct |
46 |
Correct |
6 ms |
844 KB |
Output is correct |
47 |
Correct |
7 ms |
848 KB |
Output is correct |
48 |
Correct |
7 ms |
936 KB |
Output is correct |
49 |
Correct |
5 ms |
720 KB |
Output is correct |
50 |
Correct |
1 ms |
336 KB |
Output is correct |
51 |
Correct |
219 ms |
14944 KB |
Output is correct |
52 |
Correct |
237 ms |
14940 KB |
Output is correct |
53 |
Correct |
223 ms |
15000 KB |
Output is correct |
54 |
Correct |
217 ms |
14920 KB |
Output is correct |
55 |
Correct |
212 ms |
14920 KB |
Output is correct |
56 |
Correct |
234 ms |
14992 KB |
Output is correct |
57 |
Correct |
238 ms |
14944 KB |
Output is correct |
58 |
Correct |
145 ms |
14936 KB |
Output is correct |
59 |
Correct |
147 ms |
15008 KB |
Output is correct |
60 |
Correct |
0 ms |
336 KB |
Output is correct |
61 |
Correct |
241 ms |
18768 KB |
Output is correct |
62 |
Correct |
252 ms |
18748 KB |
Output is correct |
63 |
Correct |
258 ms |
18760 KB |
Output is correct |
64 |
Correct |
238 ms |
18740 KB |
Output is correct |
65 |
Correct |
230 ms |
18760 KB |
Output is correct |
66 |
Correct |
238 ms |
18760 KB |
Output is correct |
67 |
Correct |
236 ms |
18652 KB |
Output is correct |
68 |
Correct |
306 ms |
18796 KB |
Output is correct |
69 |
Correct |
215 ms |
15052 KB |
Output is correct |
70 |
Correct |
0 ms |
324 KB |
Output is correct |