#include <iostream>
#include <vector>
#include <cstring>
#include <algorithm>
#include <map>
using namespace std;
long long int t[1200000];
long long int g[300000];
long long int left1[300000], right1[300000];
void update (int v, int tl, int tr, int h) {
if (tl == tr)
t[v]++;
else {
int tm = (tl + tr) / 2;
if (h <= tm)
update (v*2, tl, tm, h);
else
update (v*2+1, tm+1, tr, h);
t[v] = t[v*2] + t[v*2+1];
}
}
long long int sum (int v, int tl, int tr, int l, int r) {
if (l > r)
return 0;
if (l == tl && r == tr)
return t[v];
int tm = (tl + tr) / 2;
return sum (v*2, tl, tm, l, min(r,tm))
+ sum (v*2+1, tm+1, tr, max(l,tm+1), r);
}
int main(){
int n;
//freopen("69.in.txt", "r", stdin);
cin >> n;
vector<long long int>b;
for(int i = 0; i < n; i++){
cin >> g[i];
b.push_back(g[i]);
}
sort(b.begin(), b.end());
map<long long int,long long int>c;
for(int i = 0; i < b.size(); i++){
c[b[i]] = i;
}
for(int i = 0; i < n; i++){
g[i] = c[g[i]];
}
update(1, 0, n, (int)g[0]);
for(int i = 1; i < n - 1; i++){
left1[i] = sum(1, 0, n, 0, (int)g[i] - 1);
update(1, 0, n, (int)g[i]);
}
memset(t, 0, sizeof(t[0]) * 1200000);
update(1, 0, n, (int)g[n - 1]);
for(int i = n - 2; i >= 1; i--){
right1[i] = sum(1, 0, n, 0, (int)g[i] - 1);
update(1, 0, n, (int)g[i]);
}
long long int ans = 0;
for(int i = 1; i < n - 1; i++){
ans += 1LL * left1[i] * right1[i];
}
cout << ans;
return 0;
}
Compilation message
Mountains.cpp: In function 'int main()':
Mountains.cpp:42:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
42 | for(int i = 0; i < b.size(); i++){
| ~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
9676 KB |
Output is correct |
2 |
Correct |
512 ms |
37864 KB |
Output is correct |
3 |
Correct |
516 ms |
37768 KB |
Output is correct |
4 |
Correct |
516 ms |
37776 KB |
Output is correct |
5 |
Correct |
572 ms |
37760 KB |
Output is correct |
6 |
Correct |
508 ms |
37740 KB |
Output is correct |
7 |
Correct |
504 ms |
37776 KB |
Output is correct |
8 |
Correct |
508 ms |
37800 KB |
Output is correct |
9 |
Correct |
516 ms |
28676 KB |
Output is correct |
10 |
Correct |
496 ms |
28752 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
217 ms |
19188 KB |
Output is correct |
2 |
Correct |
234 ms |
19160 KB |
Output is correct |
3 |
Correct |
218 ms |
19168 KB |
Output is correct |
4 |
Correct |
229 ms |
19244 KB |
Output is correct |
5 |
Correct |
214 ms |
19136 KB |
Output is correct |
6 |
Correct |
261 ms |
19096 KB |
Output is correct |
7 |
Correct |
222 ms |
19112 KB |
Output is correct |
8 |
Correct |
211 ms |
19188 KB |
Output is correct |
9 |
Correct |
213 ms |
19112 KB |
Output is correct |
10 |
Correct |
5 ms |
9676 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
217 ms |
19188 KB |
Output is correct |
2 |
Correct |
234 ms |
19160 KB |
Output is correct |
3 |
Correct |
218 ms |
19168 KB |
Output is correct |
4 |
Correct |
229 ms |
19244 KB |
Output is correct |
5 |
Correct |
214 ms |
19136 KB |
Output is correct |
6 |
Correct |
261 ms |
19096 KB |
Output is correct |
7 |
Correct |
222 ms |
19112 KB |
Output is correct |
8 |
Correct |
211 ms |
19188 KB |
Output is correct |
9 |
Correct |
213 ms |
19112 KB |
Output is correct |
10 |
Correct |
5 ms |
9676 KB |
Output is correct |
11 |
Correct |
318 ms |
19080 KB |
Output is correct |
12 |
Correct |
308 ms |
19112 KB |
Output is correct |
13 |
Correct |
331 ms |
19160 KB |
Output is correct |
14 |
Correct |
304 ms |
19076 KB |
Output is correct |
15 |
Correct |
302 ms |
19160 KB |
Output is correct |
16 |
Correct |
354 ms |
19144 KB |
Output is correct |
17 |
Correct |
301 ms |
19104 KB |
Output is correct |
18 |
Correct |
234 ms |
19108 KB |
Output is correct |
19 |
Correct |
249 ms |
19184 KB |
Output is correct |
20 |
Correct |
5 ms |
9676 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
9676 KB |
Output is correct |
2 |
Correct |
7 ms |
9640 KB |
Output is correct |
3 |
Correct |
7 ms |
9644 KB |
Output is correct |
4 |
Correct |
7 ms |
9676 KB |
Output is correct |
5 |
Correct |
6 ms |
9676 KB |
Output is correct |
6 |
Correct |
6 ms |
9676 KB |
Output is correct |
7 |
Correct |
6 ms |
9676 KB |
Output is correct |
8 |
Correct |
6 ms |
9676 KB |
Output is correct |
9 |
Correct |
6 ms |
9676 KB |
Output is correct |
10 |
Correct |
5 ms |
9676 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
9676 KB |
Output is correct |
2 |
Correct |
7 ms |
9640 KB |
Output is correct |
3 |
Correct |
7 ms |
9644 KB |
Output is correct |
4 |
Correct |
7 ms |
9676 KB |
Output is correct |
5 |
Correct |
6 ms |
9676 KB |
Output is correct |
6 |
Correct |
6 ms |
9676 KB |
Output is correct |
7 |
Correct |
6 ms |
9676 KB |
Output is correct |
8 |
Correct |
6 ms |
9676 KB |
Output is correct |
9 |
Correct |
6 ms |
9676 KB |
Output is correct |
10 |
Correct |
5 ms |
9676 KB |
Output is correct |
11 |
Correct |
23 ms |
10616 KB |
Output is correct |
12 |
Correct |
28 ms |
10572 KB |
Output is correct |
13 |
Correct |
23 ms |
10612 KB |
Output is correct |
14 |
Correct |
24 ms |
10612 KB |
Output is correct |
15 |
Correct |
23 ms |
10564 KB |
Output is correct |
16 |
Correct |
23 ms |
10620 KB |
Output is correct |
17 |
Correct |
23 ms |
10576 KB |
Output is correct |
18 |
Correct |
21 ms |
10188 KB |
Output is correct |
19 |
Correct |
15 ms |
10092 KB |
Output is correct |
20 |
Correct |
6 ms |
9676 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
217 ms |
19188 KB |
Output is correct |
2 |
Correct |
234 ms |
19160 KB |
Output is correct |
3 |
Correct |
218 ms |
19168 KB |
Output is correct |
4 |
Correct |
229 ms |
19244 KB |
Output is correct |
5 |
Correct |
214 ms |
19136 KB |
Output is correct |
6 |
Correct |
261 ms |
19096 KB |
Output is correct |
7 |
Correct |
222 ms |
19112 KB |
Output is correct |
8 |
Correct |
211 ms |
19188 KB |
Output is correct |
9 |
Correct |
213 ms |
19112 KB |
Output is correct |
10 |
Correct |
5 ms |
9676 KB |
Output is correct |
11 |
Correct |
318 ms |
19080 KB |
Output is correct |
12 |
Correct |
308 ms |
19112 KB |
Output is correct |
13 |
Correct |
331 ms |
19160 KB |
Output is correct |
14 |
Correct |
304 ms |
19076 KB |
Output is correct |
15 |
Correct |
302 ms |
19160 KB |
Output is correct |
16 |
Correct |
354 ms |
19144 KB |
Output is correct |
17 |
Correct |
301 ms |
19104 KB |
Output is correct |
18 |
Correct |
234 ms |
19108 KB |
Output is correct |
19 |
Correct |
249 ms |
19184 KB |
Output is correct |
20 |
Correct |
5 ms |
9676 KB |
Output is correct |
21 |
Correct |
678 ms |
24968 KB |
Output is correct |
22 |
Correct |
652 ms |
24980 KB |
Output is correct |
23 |
Correct |
704 ms |
24952 KB |
Output is correct |
24 |
Correct |
669 ms |
25016 KB |
Output is correct |
25 |
Correct |
633 ms |
24948 KB |
Output is correct |
26 |
Correct |
647 ms |
25132 KB |
Output is correct |
27 |
Correct |
787 ms |
25000 KB |
Output is correct |
28 |
Correct |
355 ms |
25008 KB |
Output is correct |
29 |
Correct |
357 ms |
25016 KB |
Output is correct |
30 |
Correct |
6 ms |
9676 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
9676 KB |
Output is correct |
2 |
Correct |
512 ms |
37864 KB |
Output is correct |
3 |
Correct |
516 ms |
37768 KB |
Output is correct |
4 |
Correct |
516 ms |
37776 KB |
Output is correct |
5 |
Correct |
572 ms |
37760 KB |
Output is correct |
6 |
Correct |
508 ms |
37740 KB |
Output is correct |
7 |
Correct |
504 ms |
37776 KB |
Output is correct |
8 |
Correct |
508 ms |
37800 KB |
Output is correct |
9 |
Correct |
516 ms |
28676 KB |
Output is correct |
10 |
Correct |
496 ms |
28752 KB |
Output is correct |
11 |
Correct |
217 ms |
19188 KB |
Output is correct |
12 |
Correct |
234 ms |
19160 KB |
Output is correct |
13 |
Correct |
218 ms |
19168 KB |
Output is correct |
14 |
Correct |
229 ms |
19244 KB |
Output is correct |
15 |
Correct |
214 ms |
19136 KB |
Output is correct |
16 |
Correct |
261 ms |
19096 KB |
Output is correct |
17 |
Correct |
222 ms |
19112 KB |
Output is correct |
18 |
Correct |
211 ms |
19188 KB |
Output is correct |
19 |
Correct |
213 ms |
19112 KB |
Output is correct |
20 |
Correct |
5 ms |
9676 KB |
Output is correct |
21 |
Correct |
318 ms |
19080 KB |
Output is correct |
22 |
Correct |
308 ms |
19112 KB |
Output is correct |
23 |
Correct |
331 ms |
19160 KB |
Output is correct |
24 |
Correct |
304 ms |
19076 KB |
Output is correct |
25 |
Correct |
302 ms |
19160 KB |
Output is correct |
26 |
Correct |
354 ms |
19144 KB |
Output is correct |
27 |
Correct |
301 ms |
19104 KB |
Output is correct |
28 |
Correct |
234 ms |
19108 KB |
Output is correct |
29 |
Correct |
249 ms |
19184 KB |
Output is correct |
30 |
Correct |
5 ms |
9676 KB |
Output is correct |
31 |
Correct |
7 ms |
9676 KB |
Output is correct |
32 |
Correct |
7 ms |
9640 KB |
Output is correct |
33 |
Correct |
7 ms |
9644 KB |
Output is correct |
34 |
Correct |
7 ms |
9676 KB |
Output is correct |
35 |
Correct |
6 ms |
9676 KB |
Output is correct |
36 |
Correct |
6 ms |
9676 KB |
Output is correct |
37 |
Correct |
6 ms |
9676 KB |
Output is correct |
38 |
Correct |
6 ms |
9676 KB |
Output is correct |
39 |
Correct |
6 ms |
9676 KB |
Output is correct |
40 |
Correct |
5 ms |
9676 KB |
Output is correct |
41 |
Correct |
23 ms |
10616 KB |
Output is correct |
42 |
Correct |
28 ms |
10572 KB |
Output is correct |
43 |
Correct |
23 ms |
10612 KB |
Output is correct |
44 |
Correct |
24 ms |
10612 KB |
Output is correct |
45 |
Correct |
23 ms |
10564 KB |
Output is correct |
46 |
Correct |
23 ms |
10620 KB |
Output is correct |
47 |
Correct |
23 ms |
10576 KB |
Output is correct |
48 |
Correct |
21 ms |
10188 KB |
Output is correct |
49 |
Correct |
15 ms |
10092 KB |
Output is correct |
50 |
Correct |
6 ms |
9676 KB |
Output is correct |
51 |
Correct |
678 ms |
24968 KB |
Output is correct |
52 |
Correct |
652 ms |
24980 KB |
Output is correct |
53 |
Correct |
704 ms |
24952 KB |
Output is correct |
54 |
Correct |
669 ms |
25016 KB |
Output is correct |
55 |
Correct |
633 ms |
24948 KB |
Output is correct |
56 |
Correct |
647 ms |
25132 KB |
Output is correct |
57 |
Correct |
787 ms |
25000 KB |
Output is correct |
58 |
Correct |
355 ms |
25008 KB |
Output is correct |
59 |
Correct |
357 ms |
25016 KB |
Output is correct |
60 |
Correct |
6 ms |
9676 KB |
Output is correct |
61 |
Correct |
1069 ms |
37764 KB |
Output is correct |
62 |
Correct |
1034 ms |
37884 KB |
Output is correct |
63 |
Correct |
1034 ms |
37760 KB |
Output is correct |
64 |
Correct |
957 ms |
37816 KB |
Output is correct |
65 |
Correct |
974 ms |
37796 KB |
Output is correct |
66 |
Correct |
953 ms |
37736 KB |
Output is correct |
67 |
Correct |
952 ms |
37944 KB |
Output is correct |
68 |
Correct |
901 ms |
28712 KB |
Output is correct |
69 |
Correct |
743 ms |
27216 KB |
Output is correct |
70 |
Correct |
7 ms |
9676 KB |
Output is correct |