#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define pb push_back
#define f first
#define s second
#define ll long long
#define int long long
#define mod 1000000007
#define N 300005
using namespace std;
int a[300005],fen[4][300005],X[300005];
pair<int,int> d[300005];
void upd(int x,int idx){
while (idx < N){
fen[x][idx]+=1;
idx += (idx&(-idx));
}
}
int get(int x,int idx){
int sum=0;
while (idx > 0){
sum += fen[x][idx];
idx -= (idx&(-idx));
}
return sum;
}
main (){
int n;
cin>>n;
for (int i=1;i<=n;i++){
cin>>a[i];
d[i].f = a[i],d[i].s = i;
}
sort(d+1,d+n+1);
int m=1;
for (int i=1;i<=n;i++){
if (i > 1 && d[i - 1].f < d[i].f) m++;
a[d[i].s] = m;
}
for (int i=1;i<=n;i++){
if (a[i] > 1) X[i] = get(1,a[i] - 1);
upd(1,a[i]);
}
int ans=0;
for (int i=n;i>=1;i--){
m=0;
if (a[i] == 1) X[i]=0;
else m = get(2,a[i - 1]),X[i] *= get(2,a[i] - 1);
ans+=X[i];
upd(2,a[i]);
}
cout<<ans;
}
Compilation message
Mountains.cpp:27:7: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
27 | main (){
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
471 ms |
15096 KB |
Output is correct |
3 |
Correct |
473 ms |
16132 KB |
Output is correct |
4 |
Correct |
472 ms |
16140 KB |
Output is correct |
5 |
Correct |
473 ms |
16120 KB |
Output is correct |
6 |
Correct |
475 ms |
16248 KB |
Output is correct |
7 |
Correct |
472 ms |
15992 KB |
Output is correct |
8 |
Correct |
469 ms |
16120 KB |
Output is correct |
9 |
Correct |
477 ms |
13944 KB |
Output is correct |
10 |
Correct |
475 ms |
13816 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
141 ms |
10440 KB |
Output is correct |
2 |
Correct |
154 ms |
10376 KB |
Output is correct |
3 |
Correct |
158 ms |
10360 KB |
Output is correct |
4 |
Correct |
144 ms |
10492 KB |
Output is correct |
5 |
Correct |
163 ms |
10360 KB |
Output is correct |
6 |
Correct |
153 ms |
10452 KB |
Output is correct |
7 |
Correct |
147 ms |
10488 KB |
Output is correct |
8 |
Correct |
128 ms |
10364 KB |
Output is correct |
9 |
Correct |
125 ms |
10360 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
141 ms |
10440 KB |
Output is correct |
2 |
Correct |
154 ms |
10376 KB |
Output is correct |
3 |
Correct |
158 ms |
10360 KB |
Output is correct |
4 |
Correct |
144 ms |
10492 KB |
Output is correct |
5 |
Correct |
163 ms |
10360 KB |
Output is correct |
6 |
Correct |
153 ms |
10452 KB |
Output is correct |
7 |
Correct |
147 ms |
10488 KB |
Output is correct |
8 |
Correct |
128 ms |
10364 KB |
Output is correct |
9 |
Correct |
125 ms |
10360 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
172 ms |
10640 KB |
Output is correct |
12 |
Correct |
167 ms |
10616 KB |
Output is correct |
13 |
Correct |
164 ms |
10616 KB |
Output is correct |
14 |
Correct |
175 ms |
10584 KB |
Output is correct |
15 |
Correct |
165 ms |
10616 KB |
Output is correct |
16 |
Correct |
166 ms |
10600 KB |
Output is correct |
17 |
Correct |
166 ms |
10744 KB |
Output is correct |
18 |
Correct |
142 ms |
10620 KB |
Output is correct |
19 |
Correct |
139 ms |
10668 KB |
Output is correct |
20 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
512 KB |
Output is correct |
2 |
Correct |
1 ms |
512 KB |
Output is correct |
3 |
Correct |
1 ms |
512 KB |
Output is correct |
4 |
Correct |
1 ms |
512 KB |
Output is correct |
5 |
Correct |
2 ms |
512 KB |
Output is correct |
6 |
Correct |
1 ms |
512 KB |
Output is correct |
7 |
Correct |
2 ms |
512 KB |
Output is correct |
8 |
Correct |
1 ms |
512 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
512 KB |
Output is correct |
2 |
Correct |
1 ms |
512 KB |
Output is correct |
3 |
Correct |
1 ms |
512 KB |
Output is correct |
4 |
Correct |
1 ms |
512 KB |
Output is correct |
5 |
Correct |
2 ms |
512 KB |
Output is correct |
6 |
Correct |
1 ms |
512 KB |
Output is correct |
7 |
Correct |
2 ms |
512 KB |
Output is correct |
8 |
Correct |
1 ms |
512 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
17 ms |
1024 KB |
Output is correct |
12 |
Correct |
22 ms |
1016 KB |
Output is correct |
13 |
Correct |
17 ms |
1024 KB |
Output is correct |
14 |
Correct |
18 ms |
1024 KB |
Output is correct |
15 |
Correct |
17 ms |
1024 KB |
Output is correct |
16 |
Correct |
17 ms |
1024 KB |
Output is correct |
17 |
Correct |
17 ms |
1024 KB |
Output is correct |
18 |
Correct |
17 ms |
1024 KB |
Output is correct |
19 |
Correct |
7 ms |
768 KB |
Output is correct |
20 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
141 ms |
10440 KB |
Output is correct |
2 |
Correct |
154 ms |
10376 KB |
Output is correct |
3 |
Correct |
158 ms |
10360 KB |
Output is correct |
4 |
Correct |
144 ms |
10492 KB |
Output is correct |
5 |
Correct |
163 ms |
10360 KB |
Output is correct |
6 |
Correct |
153 ms |
10452 KB |
Output is correct |
7 |
Correct |
147 ms |
10488 KB |
Output is correct |
8 |
Correct |
128 ms |
10364 KB |
Output is correct |
9 |
Correct |
125 ms |
10360 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
172 ms |
10640 KB |
Output is correct |
12 |
Correct |
167 ms |
10616 KB |
Output is correct |
13 |
Correct |
164 ms |
10616 KB |
Output is correct |
14 |
Correct |
175 ms |
10584 KB |
Output is correct |
15 |
Correct |
165 ms |
10616 KB |
Output is correct |
16 |
Correct |
166 ms |
10600 KB |
Output is correct |
17 |
Correct |
166 ms |
10744 KB |
Output is correct |
18 |
Correct |
142 ms |
10620 KB |
Output is correct |
19 |
Correct |
139 ms |
10668 KB |
Output is correct |
20 |
Correct |
1 ms |
384 KB |
Output is correct |
21 |
Correct |
248 ms |
11976 KB |
Output is correct |
22 |
Correct |
237 ms |
11964 KB |
Output is correct |
23 |
Correct |
235 ms |
12024 KB |
Output is correct |
24 |
Correct |
232 ms |
12024 KB |
Output is correct |
25 |
Correct |
229 ms |
12024 KB |
Output is correct |
26 |
Correct |
229 ms |
12024 KB |
Output is correct |
27 |
Correct |
229 ms |
12024 KB |
Output is correct |
28 |
Correct |
197 ms |
12024 KB |
Output is correct |
29 |
Correct |
196 ms |
12024 KB |
Output is correct |
30 |
Correct |
1 ms |
512 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
471 ms |
15096 KB |
Output is correct |
3 |
Correct |
473 ms |
16132 KB |
Output is correct |
4 |
Correct |
472 ms |
16140 KB |
Output is correct |
5 |
Correct |
473 ms |
16120 KB |
Output is correct |
6 |
Correct |
475 ms |
16248 KB |
Output is correct |
7 |
Correct |
472 ms |
15992 KB |
Output is correct |
8 |
Correct |
469 ms |
16120 KB |
Output is correct |
9 |
Correct |
477 ms |
13944 KB |
Output is correct |
10 |
Correct |
475 ms |
13816 KB |
Output is correct |
11 |
Correct |
141 ms |
10440 KB |
Output is correct |
12 |
Correct |
154 ms |
10376 KB |
Output is correct |
13 |
Correct |
158 ms |
10360 KB |
Output is correct |
14 |
Correct |
144 ms |
10492 KB |
Output is correct |
15 |
Correct |
163 ms |
10360 KB |
Output is correct |
16 |
Correct |
153 ms |
10452 KB |
Output is correct |
17 |
Correct |
147 ms |
10488 KB |
Output is correct |
18 |
Correct |
128 ms |
10364 KB |
Output is correct |
19 |
Correct |
125 ms |
10360 KB |
Output is correct |
20 |
Correct |
1 ms |
384 KB |
Output is correct |
21 |
Correct |
172 ms |
10640 KB |
Output is correct |
22 |
Correct |
167 ms |
10616 KB |
Output is correct |
23 |
Correct |
164 ms |
10616 KB |
Output is correct |
24 |
Correct |
175 ms |
10584 KB |
Output is correct |
25 |
Correct |
165 ms |
10616 KB |
Output is correct |
26 |
Correct |
166 ms |
10600 KB |
Output is correct |
27 |
Correct |
166 ms |
10744 KB |
Output is correct |
28 |
Correct |
142 ms |
10620 KB |
Output is correct |
29 |
Correct |
139 ms |
10668 KB |
Output is correct |
30 |
Correct |
1 ms |
384 KB |
Output is correct |
31 |
Correct |
1 ms |
512 KB |
Output is correct |
32 |
Correct |
1 ms |
512 KB |
Output is correct |
33 |
Correct |
1 ms |
512 KB |
Output is correct |
34 |
Correct |
1 ms |
512 KB |
Output is correct |
35 |
Correct |
2 ms |
512 KB |
Output is correct |
36 |
Correct |
1 ms |
512 KB |
Output is correct |
37 |
Correct |
2 ms |
512 KB |
Output is correct |
38 |
Correct |
1 ms |
512 KB |
Output is correct |
39 |
Correct |
1 ms |
384 KB |
Output is correct |
40 |
Correct |
1 ms |
384 KB |
Output is correct |
41 |
Correct |
17 ms |
1024 KB |
Output is correct |
42 |
Correct |
22 ms |
1016 KB |
Output is correct |
43 |
Correct |
17 ms |
1024 KB |
Output is correct |
44 |
Correct |
18 ms |
1024 KB |
Output is correct |
45 |
Correct |
17 ms |
1024 KB |
Output is correct |
46 |
Correct |
17 ms |
1024 KB |
Output is correct |
47 |
Correct |
17 ms |
1024 KB |
Output is correct |
48 |
Correct |
17 ms |
1024 KB |
Output is correct |
49 |
Correct |
7 ms |
768 KB |
Output is correct |
50 |
Correct |
1 ms |
384 KB |
Output is correct |
51 |
Correct |
248 ms |
11976 KB |
Output is correct |
52 |
Correct |
237 ms |
11964 KB |
Output is correct |
53 |
Correct |
235 ms |
12024 KB |
Output is correct |
54 |
Correct |
232 ms |
12024 KB |
Output is correct |
55 |
Correct |
229 ms |
12024 KB |
Output is correct |
56 |
Correct |
229 ms |
12024 KB |
Output is correct |
57 |
Correct |
229 ms |
12024 KB |
Output is correct |
58 |
Correct |
197 ms |
12024 KB |
Output is correct |
59 |
Correct |
196 ms |
12024 KB |
Output is correct |
60 |
Correct |
1 ms |
512 KB |
Output is correct |
61 |
Correct |
505 ms |
16024 KB |
Output is correct |
62 |
Correct |
506 ms |
16248 KB |
Output is correct |
63 |
Correct |
503 ms |
15972 KB |
Output is correct |
64 |
Correct |
508 ms |
16120 KB |
Output is correct |
65 |
Correct |
513 ms |
16120 KB |
Output is correct |
66 |
Correct |
506 ms |
15992 KB |
Output is correct |
67 |
Correct |
509 ms |
16248 KB |
Output is correct |
68 |
Correct |
509 ms |
13780 KB |
Output is correct |
69 |
Correct |
239 ms |
12652 KB |
Output is correct |
70 |
Correct |
1 ms |
384 KB |
Output is correct |