#include <bits/stdc++.h>
using namespace std;
long long n, h[300010], ans=0, bit[2][300010], f[300010], cnt=0;\
unordered_map<long long, int> g;
void add(long long i, long long v, long long id){
while(i<=cnt){
bit[id][i]+=v;
i+=i&-i;
}
}
long long sum(long long i, long long id){
long long s=0;
while(i>0){
s+=bit[id][i];
i-=i&-i;
}
return s;
}
set<long long> thutu;
int main(){
//freopen("mountains.inp", "r", stdin);
//freopen("mountains.out", "w", stdout);
cin>>n;
for(int i=1;i<=n;i++)cin>>h[i], thutu.insert(h[i]);
for(auto x : thutu){
cnt++;
f[cnt]=x;
g[x]=cnt;
}
add(g[h[1]], 1, 0);
for(int i=3;i<=n;i++){
add(g[h[i]], 1, 1);
}
for(int i=2;i<n;i++){
ans+=(sum(g[h[i]]-1, 0)*sum(g[h[i]]-1, 1));
add(g[h[i]], 1, 0);
add(g[h[i+1]], -1, 1);
}
cout<<ans;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
279 ms |
41340 KB |
Output is correct |
3 |
Correct |
301 ms |
41336 KB |
Output is correct |
4 |
Correct |
284 ms |
41532 KB |
Output is correct |
5 |
Correct |
274 ms |
41356 KB |
Output is correct |
6 |
Correct |
294 ms |
41336 KB |
Output is correct |
7 |
Correct |
282 ms |
41340 KB |
Output is correct |
8 |
Correct |
294 ms |
41336 KB |
Output is correct |
9 |
Correct |
212 ms |
25408 KB |
Output is correct |
10 |
Correct |
213 ms |
25288 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
42 ms |
3160 KB |
Output is correct |
2 |
Correct |
45 ms |
3152 KB |
Output is correct |
3 |
Correct |
42 ms |
3368 KB |
Output is correct |
4 |
Correct |
38 ms |
3152 KB |
Output is correct |
5 |
Correct |
38 ms |
3164 KB |
Output is correct |
6 |
Correct |
40 ms |
3160 KB |
Output is correct |
7 |
Correct |
39 ms |
3160 KB |
Output is correct |
8 |
Correct |
31 ms |
3160 KB |
Output is correct |
9 |
Correct |
31 ms |
3164 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
42 ms |
3160 KB |
Output is correct |
2 |
Correct |
45 ms |
3152 KB |
Output is correct |
3 |
Correct |
42 ms |
3368 KB |
Output is correct |
4 |
Correct |
38 ms |
3152 KB |
Output is correct |
5 |
Correct |
38 ms |
3164 KB |
Output is correct |
6 |
Correct |
40 ms |
3160 KB |
Output is correct |
7 |
Correct |
39 ms |
3160 KB |
Output is correct |
8 |
Correct |
31 ms |
3160 KB |
Output is correct |
9 |
Correct |
31 ms |
3164 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
60 ms |
3412 KB |
Output is correct |
12 |
Correct |
55 ms |
3588 KB |
Output is correct |
13 |
Correct |
54 ms |
3640 KB |
Output is correct |
14 |
Correct |
54 ms |
3400 KB |
Output is correct |
15 |
Correct |
57 ms |
3412 KB |
Output is correct |
16 |
Correct |
56 ms |
3420 KB |
Output is correct |
17 |
Correct |
56 ms |
3536 KB |
Output is correct |
18 |
Correct |
44 ms |
3412 KB |
Output is correct |
19 |
Correct |
43 ms |
3408 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 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 |
1880 KB |
Output is correct |
12 |
Correct |
9 ms |
1616 KB |
Output is correct |
13 |
Correct |
10 ms |
1624 KB |
Output is correct |
14 |
Correct |
11 ms |
1628 KB |
Output is correct |
15 |
Correct |
9 ms |
1628 KB |
Output is correct |
16 |
Correct |
11 ms |
1692 KB |
Output is correct |
17 |
Correct |
9 ms |
1628 KB |
Output is correct |
18 |
Correct |
8 ms |
1200 KB |
Output is correct |
19 |
Correct |
3 ms |
456 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
42 ms |
3160 KB |
Output is correct |
2 |
Correct |
45 ms |
3152 KB |
Output is correct |
3 |
Correct |
42 ms |
3368 KB |
Output is correct |
4 |
Correct |
38 ms |
3152 KB |
Output is correct |
5 |
Correct |
38 ms |
3164 KB |
Output is correct |
6 |
Correct |
40 ms |
3160 KB |
Output is correct |
7 |
Correct |
39 ms |
3160 KB |
Output is correct |
8 |
Correct |
31 ms |
3160 KB |
Output is correct |
9 |
Correct |
31 ms |
3164 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
60 ms |
3412 KB |
Output is correct |
12 |
Correct |
55 ms |
3588 KB |
Output is correct |
13 |
Correct |
54 ms |
3640 KB |
Output is correct |
14 |
Correct |
54 ms |
3400 KB |
Output is correct |
15 |
Correct |
57 ms |
3412 KB |
Output is correct |
16 |
Correct |
56 ms |
3420 KB |
Output is correct |
17 |
Correct |
56 ms |
3536 KB |
Output is correct |
18 |
Correct |
44 ms |
3412 KB |
Output is correct |
19 |
Correct |
43 ms |
3408 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
170 ms |
15296 KB |
Output is correct |
22 |
Correct |
167 ms |
15384 KB |
Output is correct |
23 |
Correct |
157 ms |
15408 KB |
Output is correct |
24 |
Correct |
163 ms |
15300 KB |
Output is correct |
25 |
Correct |
166 ms |
15336 KB |
Output is correct |
26 |
Correct |
169 ms |
15556 KB |
Output is correct |
27 |
Correct |
172 ms |
15364 KB |
Output is correct |
28 |
Correct |
112 ms |
15304 KB |
Output is correct |
29 |
Correct |
109 ms |
15300 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
279 ms |
41340 KB |
Output is correct |
3 |
Correct |
301 ms |
41336 KB |
Output is correct |
4 |
Correct |
284 ms |
41532 KB |
Output is correct |
5 |
Correct |
274 ms |
41356 KB |
Output is correct |
6 |
Correct |
294 ms |
41336 KB |
Output is correct |
7 |
Correct |
282 ms |
41340 KB |
Output is correct |
8 |
Correct |
294 ms |
41336 KB |
Output is correct |
9 |
Correct |
212 ms |
25408 KB |
Output is correct |
10 |
Correct |
213 ms |
25288 KB |
Output is correct |
11 |
Correct |
42 ms |
3160 KB |
Output is correct |
12 |
Correct |
45 ms |
3152 KB |
Output is correct |
13 |
Correct |
42 ms |
3368 KB |
Output is correct |
14 |
Correct |
38 ms |
3152 KB |
Output is correct |
15 |
Correct |
38 ms |
3164 KB |
Output is correct |
16 |
Correct |
40 ms |
3160 KB |
Output is correct |
17 |
Correct |
39 ms |
3160 KB |
Output is correct |
18 |
Correct |
31 ms |
3160 KB |
Output is correct |
19 |
Correct |
31 ms |
3164 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
60 ms |
3412 KB |
Output is correct |
22 |
Correct |
55 ms |
3588 KB |
Output is correct |
23 |
Correct |
54 ms |
3640 KB |
Output is correct |
24 |
Correct |
54 ms |
3400 KB |
Output is correct |
25 |
Correct |
57 ms |
3412 KB |
Output is correct |
26 |
Correct |
56 ms |
3420 KB |
Output is correct |
27 |
Correct |
56 ms |
3536 KB |
Output is correct |
28 |
Correct |
44 ms |
3412 KB |
Output is correct |
29 |
Correct |
43 ms |
3408 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
1 ms |
344 KB |
Output is correct |
32 |
Correct |
1 ms |
348 KB |
Output is correct |
33 |
Correct |
1 ms |
348 KB |
Output is correct |
34 |
Correct |
1 ms |
348 KB |
Output is correct |
35 |
Correct |
1 ms |
344 KB |
Output is correct |
36 |
Correct |
1 ms |
348 KB |
Output is correct |
37 |
Correct |
1 ms |
348 KB |
Output is correct |
38 |
Correct |
1 ms |
348 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 |
1880 KB |
Output is correct |
42 |
Correct |
9 ms |
1616 KB |
Output is correct |
43 |
Correct |
10 ms |
1624 KB |
Output is correct |
44 |
Correct |
11 ms |
1628 KB |
Output is correct |
45 |
Correct |
9 ms |
1628 KB |
Output is correct |
46 |
Correct |
11 ms |
1692 KB |
Output is correct |
47 |
Correct |
9 ms |
1628 KB |
Output is correct |
48 |
Correct |
8 ms |
1200 KB |
Output is correct |
49 |
Correct |
3 ms |
456 KB |
Output is correct |
50 |
Correct |
0 ms |
348 KB |
Output is correct |
51 |
Correct |
170 ms |
15296 KB |
Output is correct |
52 |
Correct |
167 ms |
15384 KB |
Output is correct |
53 |
Correct |
157 ms |
15408 KB |
Output is correct |
54 |
Correct |
163 ms |
15300 KB |
Output is correct |
55 |
Correct |
166 ms |
15336 KB |
Output is correct |
56 |
Correct |
169 ms |
15556 KB |
Output is correct |
57 |
Correct |
172 ms |
15364 KB |
Output is correct |
58 |
Correct |
112 ms |
15304 KB |
Output is correct |
59 |
Correct |
109 ms |
15300 KB |
Output is correct |
60 |
Correct |
0 ms |
348 KB |
Output is correct |
61 |
Correct |
397 ms |
41820 KB |
Output is correct |
62 |
Correct |
410 ms |
41424 KB |
Output is correct |
63 |
Correct |
401 ms |
41592 KB |
Output is correct |
64 |
Correct |
379 ms |
41336 KB |
Output is correct |
65 |
Correct |
419 ms |
41380 KB |
Output is correct |
66 |
Correct |
400 ms |
41452 KB |
Output is correct |
67 |
Correct |
396 ms |
41588 KB |
Output is correct |
68 |
Correct |
279 ms |
25296 KB |
Output is correct |
69 |
Correct |
174 ms |
19020 KB |
Output is correct |
70 |
Correct |
1 ms |
344 KB |
Output is correct |