#include<bits/stdc++.h>
using namespace std;
const int N=3e5+5;
long long tree[N],h[N],ans,b[N],k,i,bef,n,ind[N];
pair<long long,long long>a[N];
void update(int ind,int val){
for(ind;ind<=i;ind+=ind&(-ind)){
tree[ind]+=val;
}
}
int getans(int ind){
int pas=0;
for(ind;ind>=1;ind-=ind&(-ind)){
pas+=tree[ind];
}
return pas;
}
int main(){
cin>>n;
for(k=1;k<=n;k++){
cin>>h[k];
a[k].first=h[k];
a[k].second=k;
}
sort(a+1,a+n+1); bef=-1;
for(k=1;k<=n;k++){
if(a[k].first!=bef){
bef=a[k].first;
i++;
}
ind[a[k].second]=i;
}
for(k=1;k<=n;k++){
update(ind[k],1);
if(ind[k]!=1) b[k]=getans(ind[k]-1);
// cout<<k<<" "<<b[k]<<endl;
}
for(k=1;k<=n;k++){
update(ind[k],-1);
}
for(k=n;k>=1;k--){
update(ind[k],1);
if(ind[k]!=1)ans+=b[k]*(getans(ind[k]-1));
}
cout<<ans;
}
Compilation message
Mountains.cpp: In function 'void update(int, int)':
Mountains.cpp:8:16: warning: statement has no effect [-Wunused-value]
8 | for(ind;ind<=i;ind+=ind&(-ind)){
| ^~~
Mountains.cpp: In function 'int getans(int)':
Mountains.cpp:14:16: warning: statement has no effect [-Wunused-value]
14 | for(ind;ind>=1;ind-=ind&(-ind)){
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
483 ms |
14620 KB |
Output is correct |
3 |
Correct |
477 ms |
14712 KB |
Output is correct |
4 |
Correct |
484 ms |
14712 KB |
Output is correct |
5 |
Correct |
484 ms |
14584 KB |
Output is correct |
6 |
Correct |
479 ms |
14712 KB |
Output is correct |
7 |
Correct |
493 ms |
14864 KB |
Output is correct |
8 |
Correct |
498 ms |
14684 KB |
Output is correct |
9 |
Correct |
483 ms |
13560 KB |
Output is correct |
10 |
Correct |
487 ms |
13560 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
123 ms |
12280 KB |
Output is correct |
2 |
Correct |
124 ms |
12412 KB |
Output is correct |
3 |
Correct |
121 ms |
12256 KB |
Output is correct |
4 |
Correct |
118 ms |
12280 KB |
Output is correct |
5 |
Correct |
122 ms |
12408 KB |
Output is correct |
6 |
Correct |
125 ms |
12280 KB |
Output is correct |
7 |
Correct |
121 ms |
12280 KB |
Output is correct |
8 |
Correct |
98 ms |
11128 KB |
Output is correct |
9 |
Correct |
97 ms |
11128 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
123 ms |
12280 KB |
Output is correct |
2 |
Correct |
124 ms |
12412 KB |
Output is correct |
3 |
Correct |
121 ms |
12256 KB |
Output is correct |
4 |
Correct |
118 ms |
12280 KB |
Output is correct |
5 |
Correct |
122 ms |
12408 KB |
Output is correct |
6 |
Correct |
125 ms |
12280 KB |
Output is correct |
7 |
Correct |
121 ms |
12280 KB |
Output is correct |
8 |
Correct |
98 ms |
11128 KB |
Output is correct |
9 |
Correct |
97 ms |
11128 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
155 ms |
12280 KB |
Output is correct |
12 |
Correct |
154 ms |
12280 KB |
Output is correct |
13 |
Correct |
155 ms |
12280 KB |
Output is correct |
14 |
Correct |
156 ms |
12408 KB |
Output is correct |
15 |
Correct |
154 ms |
12408 KB |
Output is correct |
16 |
Correct |
156 ms |
12280 KB |
Output is correct |
17 |
Correct |
156 ms |
12408 KB |
Output is correct |
18 |
Correct |
124 ms |
12284 KB |
Output is correct |
19 |
Correct |
124 ms |
12280 KB |
Output is correct |
20 |
Correct |
0 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 |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
2 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 |
0 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 |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
2 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 |
0 ms |
384 KB |
Output is correct |
11 |
Correct |
17 ms |
1068 KB |
Output is correct |
12 |
Correct |
17 ms |
1024 KB |
Output is correct |
13 |
Correct |
17 ms |
1024 KB |
Output is correct |
14 |
Correct |
18 ms |
1024 KB |
Output is correct |
15 |
Correct |
18 ms |
1024 KB |
Output is correct |
16 |
Correct |
18 ms |
1024 KB |
Output is correct |
17 |
Correct |
18 ms |
1024 KB |
Output is correct |
18 |
Correct |
18 ms |
1016 KB |
Output is correct |
19 |
Correct |
6 ms |
896 KB |
Output is correct |
20 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
123 ms |
12280 KB |
Output is correct |
2 |
Correct |
124 ms |
12412 KB |
Output is correct |
3 |
Correct |
121 ms |
12256 KB |
Output is correct |
4 |
Correct |
118 ms |
12280 KB |
Output is correct |
5 |
Correct |
122 ms |
12408 KB |
Output is correct |
6 |
Correct |
125 ms |
12280 KB |
Output is correct |
7 |
Correct |
121 ms |
12280 KB |
Output is correct |
8 |
Correct |
98 ms |
11128 KB |
Output is correct |
9 |
Correct |
97 ms |
11128 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
155 ms |
12280 KB |
Output is correct |
12 |
Correct |
154 ms |
12280 KB |
Output is correct |
13 |
Correct |
155 ms |
12280 KB |
Output is correct |
14 |
Correct |
156 ms |
12408 KB |
Output is correct |
15 |
Correct |
154 ms |
12408 KB |
Output is correct |
16 |
Correct |
156 ms |
12280 KB |
Output is correct |
17 |
Correct |
156 ms |
12408 KB |
Output is correct |
18 |
Correct |
124 ms |
12284 KB |
Output is correct |
19 |
Correct |
124 ms |
12280 KB |
Output is correct |
20 |
Correct |
0 ms |
384 KB |
Output is correct |
21 |
Correct |
241 ms |
13096 KB |
Output is correct |
22 |
Correct |
238 ms |
13176 KB |
Output is correct |
23 |
Correct |
235 ms |
13048 KB |
Output is correct |
24 |
Correct |
237 ms |
13048 KB |
Output is correct |
25 |
Correct |
238 ms |
13052 KB |
Output is correct |
26 |
Correct |
235 ms |
13048 KB |
Output is correct |
27 |
Correct |
236 ms |
13180 KB |
Output is correct |
28 |
Correct |
203 ms |
13176 KB |
Output is correct |
29 |
Correct |
200 ms |
13176 KB |
Output is correct |
30 |
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 |
483 ms |
14620 KB |
Output is correct |
3 |
Correct |
477 ms |
14712 KB |
Output is correct |
4 |
Correct |
484 ms |
14712 KB |
Output is correct |
5 |
Correct |
484 ms |
14584 KB |
Output is correct |
6 |
Correct |
479 ms |
14712 KB |
Output is correct |
7 |
Correct |
493 ms |
14864 KB |
Output is correct |
8 |
Correct |
498 ms |
14684 KB |
Output is correct |
9 |
Correct |
483 ms |
13560 KB |
Output is correct |
10 |
Correct |
487 ms |
13560 KB |
Output is correct |
11 |
Correct |
123 ms |
12280 KB |
Output is correct |
12 |
Correct |
124 ms |
12412 KB |
Output is correct |
13 |
Correct |
121 ms |
12256 KB |
Output is correct |
14 |
Correct |
118 ms |
12280 KB |
Output is correct |
15 |
Correct |
122 ms |
12408 KB |
Output is correct |
16 |
Correct |
125 ms |
12280 KB |
Output is correct |
17 |
Correct |
121 ms |
12280 KB |
Output is correct |
18 |
Correct |
98 ms |
11128 KB |
Output is correct |
19 |
Correct |
97 ms |
11128 KB |
Output is correct |
20 |
Correct |
1 ms |
384 KB |
Output is correct |
21 |
Correct |
155 ms |
12280 KB |
Output is correct |
22 |
Correct |
154 ms |
12280 KB |
Output is correct |
23 |
Correct |
155 ms |
12280 KB |
Output is correct |
24 |
Correct |
156 ms |
12408 KB |
Output is correct |
25 |
Correct |
154 ms |
12408 KB |
Output is correct |
26 |
Correct |
156 ms |
12280 KB |
Output is correct |
27 |
Correct |
156 ms |
12408 KB |
Output is correct |
28 |
Correct |
124 ms |
12284 KB |
Output is correct |
29 |
Correct |
124 ms |
12280 KB |
Output is correct |
30 |
Correct |
0 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 |
384 KB |
Output is correct |
34 |
Correct |
1 ms |
384 KB |
Output is correct |
35 |
Correct |
1 ms |
384 KB |
Output is correct |
36 |
Correct |
2 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 |
0 ms |
384 KB |
Output is correct |
41 |
Correct |
17 ms |
1068 KB |
Output is correct |
42 |
Correct |
17 ms |
1024 KB |
Output is correct |
43 |
Correct |
17 ms |
1024 KB |
Output is correct |
44 |
Correct |
18 ms |
1024 KB |
Output is correct |
45 |
Correct |
18 ms |
1024 KB |
Output is correct |
46 |
Correct |
18 ms |
1024 KB |
Output is correct |
47 |
Correct |
18 ms |
1024 KB |
Output is correct |
48 |
Correct |
18 ms |
1016 KB |
Output is correct |
49 |
Correct |
6 ms |
896 KB |
Output is correct |
50 |
Correct |
1 ms |
384 KB |
Output is correct |
51 |
Correct |
241 ms |
13096 KB |
Output is correct |
52 |
Correct |
238 ms |
13176 KB |
Output is correct |
53 |
Correct |
235 ms |
13048 KB |
Output is correct |
54 |
Correct |
237 ms |
13048 KB |
Output is correct |
55 |
Correct |
238 ms |
13052 KB |
Output is correct |
56 |
Correct |
235 ms |
13048 KB |
Output is correct |
57 |
Correct |
236 ms |
13180 KB |
Output is correct |
58 |
Correct |
203 ms |
13176 KB |
Output is correct |
59 |
Correct |
200 ms |
13176 KB |
Output is correct |
60 |
Correct |
1 ms |
384 KB |
Output is correct |
61 |
Correct |
537 ms |
14808 KB |
Output is correct |
62 |
Correct |
557 ms |
14688 KB |
Output is correct |
63 |
Correct |
542 ms |
14840 KB |
Output is correct |
64 |
Correct |
520 ms |
14640 KB |
Output is correct |
65 |
Correct |
517 ms |
14584 KB |
Output is correct |
66 |
Correct |
512 ms |
14840 KB |
Output is correct |
67 |
Correct |
510 ms |
14712 KB |
Output is correct |
68 |
Correct |
519 ms |
13532 KB |
Output is correct |
69 |
Correct |
243 ms |
13436 KB |
Output is correct |
70 |
Correct |
1 ms |
384 KB |
Output is correct |