#include<bits/stdc++.h>
#define int long long
using namespace std;
int ar[300005];
int id[300005];
int l[300005];
int r[300005];
vector<int>v;
struct fenwick{
int info[300005];
void upd(int x,int val){
for(int i=x;i<=300000;i+=i&-i){
info[i]+=val;
}
}
int fsum(int x){
int sum=0;
for(int i=x;i>0;i-=i&-i){
sum+=info[i];
}
return sum;
}
}fwl,fwr;
int32_t main(){
int n;cin>>n;
for(int i=0;i<n;i++){
cin>>ar[i];
v.push_back(ar[i]);
}
sort(v.begin(),v.end());
for(int i=0;i<n;i++){
id[i]=lower_bound(v.begin(),v.end(),ar[i])-v.begin()+1;
}
for(int i=0;i<n;i++){
l[i]=fwl.fsum(id[i]-1);
fwl.upd(id[i],1);
}
for(int i=n-1;i>0;i--){
r[i]=fwr.fsum(id[i]-1);
fwr.upd(id[i],1);
}
int ans=0;
for(int i=0;i<n;i++){
ans+=l[i]*r[i];
}
cout<<ans<<"\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
12632 KB |
Output is correct |
2 |
Correct |
184 ms |
22540 KB |
Output is correct |
3 |
Correct |
173 ms |
22312 KB |
Output is correct |
4 |
Correct |
185 ms |
23060 KB |
Output is correct |
5 |
Correct |
170 ms |
23276 KB |
Output is correct |
6 |
Correct |
170 ms |
22456 KB |
Output is correct |
7 |
Correct |
174 ms |
22408 KB |
Output is correct |
8 |
Correct |
200 ms |
23988 KB |
Output is correct |
9 |
Correct |
171 ms |
22392 KB |
Output is correct |
10 |
Correct |
180 ms |
23484 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
86 ms |
16240 KB |
Output is correct |
2 |
Correct |
85 ms |
13392 KB |
Output is correct |
3 |
Correct |
79 ms |
14072 KB |
Output is correct |
4 |
Correct |
85 ms |
13620 KB |
Output is correct |
5 |
Correct |
81 ms |
14776 KB |
Output is correct |
6 |
Correct |
90 ms |
16848 KB |
Output is correct |
7 |
Correct |
84 ms |
15908 KB |
Output is correct |
8 |
Correct |
67 ms |
16312 KB |
Output is correct |
9 |
Correct |
64 ms |
15360 KB |
Output is correct |
10 |
Correct |
2 ms |
12636 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
86 ms |
16240 KB |
Output is correct |
2 |
Correct |
85 ms |
13392 KB |
Output is correct |
3 |
Correct |
79 ms |
14072 KB |
Output is correct |
4 |
Correct |
85 ms |
13620 KB |
Output is correct |
5 |
Correct |
81 ms |
14776 KB |
Output is correct |
6 |
Correct |
90 ms |
16848 KB |
Output is correct |
7 |
Correct |
84 ms |
15908 KB |
Output is correct |
8 |
Correct |
67 ms |
16312 KB |
Output is correct |
9 |
Correct |
64 ms |
15360 KB |
Output is correct |
10 |
Correct |
2 ms |
12636 KB |
Output is correct |
11 |
Correct |
120 ms |
17576 KB |
Output is correct |
12 |
Correct |
124 ms |
16868 KB |
Output is correct |
13 |
Correct |
106 ms |
15748 KB |
Output is correct |
14 |
Correct |
112 ms |
15608 KB |
Output is correct |
15 |
Correct |
110 ms |
16648 KB |
Output is correct |
16 |
Correct |
120 ms |
17080 KB |
Output is correct |
17 |
Correct |
115 ms |
16056 KB |
Output is correct |
18 |
Correct |
65 ms |
16820 KB |
Output is correct |
19 |
Correct |
59 ms |
17900 KB |
Output is correct |
20 |
Correct |
3 ms |
10584 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
10584 KB |
Output is correct |
2 |
Correct |
2 ms |
10692 KB |
Output is correct |
3 |
Correct |
2 ms |
10588 KB |
Output is correct |
4 |
Correct |
3 ms |
10588 KB |
Output is correct |
5 |
Correct |
2 ms |
10588 KB |
Output is correct |
6 |
Correct |
2 ms |
10584 KB |
Output is correct |
7 |
Correct |
2 ms |
10588 KB |
Output is correct |
8 |
Correct |
2 ms |
10840 KB |
Output is correct |
9 |
Correct |
2 ms |
10588 KB |
Output is correct |
10 |
Correct |
1 ms |
10584 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
10584 KB |
Output is correct |
2 |
Correct |
2 ms |
10692 KB |
Output is correct |
3 |
Correct |
2 ms |
10588 KB |
Output is correct |
4 |
Correct |
3 ms |
10588 KB |
Output is correct |
5 |
Correct |
2 ms |
10588 KB |
Output is correct |
6 |
Correct |
2 ms |
10584 KB |
Output is correct |
7 |
Correct |
2 ms |
10588 KB |
Output is correct |
8 |
Correct |
2 ms |
10840 KB |
Output is correct |
9 |
Correct |
2 ms |
10588 KB |
Output is correct |
10 |
Correct |
1 ms |
10584 KB |
Output is correct |
11 |
Correct |
9 ms |
11100 KB |
Output is correct |
12 |
Correct |
10 ms |
11096 KB |
Output is correct |
13 |
Correct |
9 ms |
11096 KB |
Output is correct |
14 |
Correct |
8 ms |
11100 KB |
Output is correct |
15 |
Correct |
8 ms |
11100 KB |
Output is correct |
16 |
Correct |
8 ms |
11068 KB |
Output is correct |
17 |
Correct |
10 ms |
11096 KB |
Output is correct |
18 |
Correct |
9 ms |
11296 KB |
Output is correct |
19 |
Correct |
5 ms |
11100 KB |
Output is correct |
20 |
Correct |
2 ms |
12636 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
86 ms |
16240 KB |
Output is correct |
2 |
Correct |
85 ms |
13392 KB |
Output is correct |
3 |
Correct |
79 ms |
14072 KB |
Output is correct |
4 |
Correct |
85 ms |
13620 KB |
Output is correct |
5 |
Correct |
81 ms |
14776 KB |
Output is correct |
6 |
Correct |
90 ms |
16848 KB |
Output is correct |
7 |
Correct |
84 ms |
15908 KB |
Output is correct |
8 |
Correct |
67 ms |
16312 KB |
Output is correct |
9 |
Correct |
64 ms |
15360 KB |
Output is correct |
10 |
Correct |
2 ms |
12636 KB |
Output is correct |
11 |
Correct |
120 ms |
17576 KB |
Output is correct |
12 |
Correct |
124 ms |
16868 KB |
Output is correct |
13 |
Correct |
106 ms |
15748 KB |
Output is correct |
14 |
Correct |
112 ms |
15608 KB |
Output is correct |
15 |
Correct |
110 ms |
16648 KB |
Output is correct |
16 |
Correct |
120 ms |
17080 KB |
Output is correct |
17 |
Correct |
115 ms |
16056 KB |
Output is correct |
18 |
Correct |
65 ms |
16820 KB |
Output is correct |
19 |
Correct |
59 ms |
17900 KB |
Output is correct |
20 |
Correct |
3 ms |
10584 KB |
Output is correct |
21 |
Correct |
157 ms |
19372 KB |
Output is correct |
22 |
Correct |
157 ms |
18852 KB |
Output is correct |
23 |
Correct |
158 ms |
19020 KB |
Output is correct |
24 |
Correct |
153 ms |
19572 KB |
Output is correct |
25 |
Correct |
160 ms |
19776 KB |
Output is correct |
26 |
Correct |
159 ms |
18864 KB |
Output is correct |
27 |
Correct |
163 ms |
19440 KB |
Output is correct |
28 |
Correct |
91 ms |
19124 KB |
Output is correct |
29 |
Correct |
92 ms |
19896 KB |
Output is correct |
30 |
Correct |
2 ms |
10588 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
12632 KB |
Output is correct |
2 |
Correct |
184 ms |
22540 KB |
Output is correct |
3 |
Correct |
173 ms |
22312 KB |
Output is correct |
4 |
Correct |
185 ms |
23060 KB |
Output is correct |
5 |
Correct |
170 ms |
23276 KB |
Output is correct |
6 |
Correct |
170 ms |
22456 KB |
Output is correct |
7 |
Correct |
174 ms |
22408 KB |
Output is correct |
8 |
Correct |
200 ms |
23988 KB |
Output is correct |
9 |
Correct |
171 ms |
22392 KB |
Output is correct |
10 |
Correct |
180 ms |
23484 KB |
Output is correct |
11 |
Correct |
86 ms |
16240 KB |
Output is correct |
12 |
Correct |
85 ms |
13392 KB |
Output is correct |
13 |
Correct |
79 ms |
14072 KB |
Output is correct |
14 |
Correct |
85 ms |
13620 KB |
Output is correct |
15 |
Correct |
81 ms |
14776 KB |
Output is correct |
16 |
Correct |
90 ms |
16848 KB |
Output is correct |
17 |
Correct |
84 ms |
15908 KB |
Output is correct |
18 |
Correct |
67 ms |
16312 KB |
Output is correct |
19 |
Correct |
64 ms |
15360 KB |
Output is correct |
20 |
Correct |
2 ms |
12636 KB |
Output is correct |
21 |
Correct |
120 ms |
17576 KB |
Output is correct |
22 |
Correct |
124 ms |
16868 KB |
Output is correct |
23 |
Correct |
106 ms |
15748 KB |
Output is correct |
24 |
Correct |
112 ms |
15608 KB |
Output is correct |
25 |
Correct |
110 ms |
16648 KB |
Output is correct |
26 |
Correct |
120 ms |
17080 KB |
Output is correct |
27 |
Correct |
115 ms |
16056 KB |
Output is correct |
28 |
Correct |
65 ms |
16820 KB |
Output is correct |
29 |
Correct |
59 ms |
17900 KB |
Output is correct |
30 |
Correct |
3 ms |
10584 KB |
Output is correct |
31 |
Correct |
2 ms |
10584 KB |
Output is correct |
32 |
Correct |
2 ms |
10692 KB |
Output is correct |
33 |
Correct |
2 ms |
10588 KB |
Output is correct |
34 |
Correct |
3 ms |
10588 KB |
Output is correct |
35 |
Correct |
2 ms |
10588 KB |
Output is correct |
36 |
Correct |
2 ms |
10584 KB |
Output is correct |
37 |
Correct |
2 ms |
10588 KB |
Output is correct |
38 |
Correct |
2 ms |
10840 KB |
Output is correct |
39 |
Correct |
2 ms |
10588 KB |
Output is correct |
40 |
Correct |
1 ms |
10584 KB |
Output is correct |
41 |
Correct |
9 ms |
11100 KB |
Output is correct |
42 |
Correct |
10 ms |
11096 KB |
Output is correct |
43 |
Correct |
9 ms |
11096 KB |
Output is correct |
44 |
Correct |
8 ms |
11100 KB |
Output is correct |
45 |
Correct |
8 ms |
11100 KB |
Output is correct |
46 |
Correct |
8 ms |
11068 KB |
Output is correct |
47 |
Correct |
10 ms |
11096 KB |
Output is correct |
48 |
Correct |
9 ms |
11296 KB |
Output is correct |
49 |
Correct |
5 ms |
11100 KB |
Output is correct |
50 |
Correct |
2 ms |
12636 KB |
Output is correct |
51 |
Correct |
157 ms |
19372 KB |
Output is correct |
52 |
Correct |
157 ms |
18852 KB |
Output is correct |
53 |
Correct |
158 ms |
19020 KB |
Output is correct |
54 |
Correct |
153 ms |
19572 KB |
Output is correct |
55 |
Correct |
160 ms |
19776 KB |
Output is correct |
56 |
Correct |
159 ms |
18864 KB |
Output is correct |
57 |
Correct |
163 ms |
19440 KB |
Output is correct |
58 |
Correct |
91 ms |
19124 KB |
Output is correct |
59 |
Correct |
92 ms |
19896 KB |
Output is correct |
60 |
Correct |
2 ms |
10588 KB |
Output is correct |
61 |
Correct |
245 ms |
22968 KB |
Output is correct |
62 |
Correct |
248 ms |
23648 KB |
Output is correct |
63 |
Correct |
247 ms |
22932 KB |
Output is correct |
64 |
Correct |
238 ms |
23120 KB |
Output is correct |
65 |
Correct |
249 ms |
22520 KB |
Output is correct |
66 |
Correct |
236 ms |
22352 KB |
Output is correct |
67 |
Correct |
244 ms |
22968 KB |
Output is correct |
68 |
Correct |
251 ms |
22376 KB |
Output is correct |
69 |
Correct |
157 ms |
20572 KB |
Output is correct |
70 |
Correct |
2 ms |
12636 KB |
Output is correct |