#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int mxn=300005;
int n;
ll fwt[mxn], h[mxn], tmp[mxn], lf[mxn], rg[mxn];
map<ll, ll>mp;
void upd(int x, int v){for(; x<mxn; x+=x&-x) fwt[x]+=v;}
int que(int x){ll ans=0; for(; x>0; x-=x&-x) ans+=fwt[x]; return ans;}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin>>n;
for(int i=0; i<n; i++){cin>>h[i]; tmp[i]=h[i];}
sort(tmp, tmp+n); int cnt=1;
for(int i=0; i<n; i++){
if(i==0) mp[tmp[i]]=cnt;
else if(tmp[i]>tmp[i-1]) {mp[tmp[i]]=cnt+1; cnt++;}
else mp[tmp[i]]=cnt;
}
for(int i=0; i<n; i++) h[i]=mp[h[i]]; //coordinate compression
// for(int i=0; i<n; i++) cout<<h[i]<<" "; cout<<endl;
memset(fwt, 0, sizeof(fwt));
for(int i=0; i<n; i++){
lf[i]=que(h[i]-1);
upd(h[i], 1);
}
for(int i=0; i<n; i++) rg[i]=que(h[i]-1)-lf[i];
ll ans=0ll;
for(int i=0; i<n; i++) ans+=lf[i]*rg[i];
cout<<ans<<endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
2688 KB |
Output is correct |
2 |
Correct |
205 ms |
36192 KB |
Output is correct |
3 |
Correct |
218 ms |
36216 KB |
Output is correct |
4 |
Correct |
228 ms |
36220 KB |
Output is correct |
5 |
Correct |
227 ms |
36216 KB |
Output is correct |
6 |
Correct |
231 ms |
36216 KB |
Output is correct |
7 |
Correct |
242 ms |
36216 KB |
Output is correct |
8 |
Correct |
229 ms |
36228 KB |
Output is correct |
9 |
Correct |
203 ms |
27128 KB |
Output is correct |
10 |
Correct |
210 ms |
27260 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
58 ms |
12664 KB |
Output is correct |
2 |
Correct |
55 ms |
12664 KB |
Output is correct |
3 |
Correct |
54 ms |
12664 KB |
Output is correct |
4 |
Correct |
54 ms |
12692 KB |
Output is correct |
5 |
Correct |
55 ms |
12664 KB |
Output is correct |
6 |
Correct |
55 ms |
12592 KB |
Output is correct |
7 |
Correct |
55 ms |
12664 KB |
Output is correct |
8 |
Correct |
47 ms |
12664 KB |
Output is correct |
9 |
Correct |
48 ms |
12664 KB |
Output is correct |
10 |
Correct |
5 ms |
2688 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
58 ms |
12664 KB |
Output is correct |
2 |
Correct |
55 ms |
12664 KB |
Output is correct |
3 |
Correct |
54 ms |
12664 KB |
Output is correct |
4 |
Correct |
54 ms |
12692 KB |
Output is correct |
5 |
Correct |
55 ms |
12664 KB |
Output is correct |
6 |
Correct |
55 ms |
12592 KB |
Output is correct |
7 |
Correct |
55 ms |
12664 KB |
Output is correct |
8 |
Correct |
47 ms |
12664 KB |
Output is correct |
9 |
Correct |
48 ms |
12664 KB |
Output is correct |
10 |
Correct |
5 ms |
2688 KB |
Output is correct |
11 |
Correct |
79 ms |
12884 KB |
Output is correct |
12 |
Correct |
77 ms |
12920 KB |
Output is correct |
13 |
Correct |
79 ms |
12920 KB |
Output is correct |
14 |
Correct |
72 ms |
12920 KB |
Output is correct |
15 |
Correct |
74 ms |
12920 KB |
Output is correct |
16 |
Correct |
73 ms |
12920 KB |
Output is correct |
17 |
Correct |
73 ms |
12920 KB |
Output is correct |
18 |
Correct |
53 ms |
12920 KB |
Output is correct |
19 |
Correct |
55 ms |
12924 KB |
Output is correct |
20 |
Correct |
5 ms |
2688 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
2816 KB |
Output is correct |
2 |
Correct |
6 ms |
2816 KB |
Output is correct |
3 |
Correct |
6 ms |
2816 KB |
Output is correct |
4 |
Correct |
6 ms |
2816 KB |
Output is correct |
5 |
Correct |
6 ms |
2816 KB |
Output is correct |
6 |
Correct |
6 ms |
2816 KB |
Output is correct |
7 |
Correct |
6 ms |
2816 KB |
Output is correct |
8 |
Correct |
6 ms |
2816 KB |
Output is correct |
9 |
Correct |
6 ms |
2816 KB |
Output is correct |
10 |
Correct |
5 ms |
2688 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
2816 KB |
Output is correct |
2 |
Correct |
6 ms |
2816 KB |
Output is correct |
3 |
Correct |
6 ms |
2816 KB |
Output is correct |
4 |
Correct |
6 ms |
2816 KB |
Output is correct |
5 |
Correct |
6 ms |
2816 KB |
Output is correct |
6 |
Correct |
6 ms |
2816 KB |
Output is correct |
7 |
Correct |
6 ms |
2816 KB |
Output is correct |
8 |
Correct |
6 ms |
2816 KB |
Output is correct |
9 |
Correct |
6 ms |
2816 KB |
Output is correct |
10 |
Correct |
5 ms |
2688 KB |
Output is correct |
11 |
Correct |
12 ms |
3840 KB |
Output is correct |
12 |
Correct |
13 ms |
3840 KB |
Output is correct |
13 |
Correct |
13 ms |
3840 KB |
Output is correct |
14 |
Correct |
13 ms |
3840 KB |
Output is correct |
15 |
Correct |
13 ms |
3840 KB |
Output is correct |
16 |
Correct |
14 ms |
3968 KB |
Output is correct |
17 |
Correct |
13 ms |
3840 KB |
Output is correct |
18 |
Correct |
11 ms |
3456 KB |
Output is correct |
19 |
Correct |
9 ms |
3072 KB |
Output is correct |
20 |
Correct |
6 ms |
2688 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
58 ms |
12664 KB |
Output is correct |
2 |
Correct |
55 ms |
12664 KB |
Output is correct |
3 |
Correct |
54 ms |
12664 KB |
Output is correct |
4 |
Correct |
54 ms |
12692 KB |
Output is correct |
5 |
Correct |
55 ms |
12664 KB |
Output is correct |
6 |
Correct |
55 ms |
12592 KB |
Output is correct |
7 |
Correct |
55 ms |
12664 KB |
Output is correct |
8 |
Correct |
47 ms |
12664 KB |
Output is correct |
9 |
Correct |
48 ms |
12664 KB |
Output is correct |
10 |
Correct |
5 ms |
2688 KB |
Output is correct |
11 |
Correct |
79 ms |
12884 KB |
Output is correct |
12 |
Correct |
77 ms |
12920 KB |
Output is correct |
13 |
Correct |
79 ms |
12920 KB |
Output is correct |
14 |
Correct |
72 ms |
12920 KB |
Output is correct |
15 |
Correct |
74 ms |
12920 KB |
Output is correct |
16 |
Correct |
73 ms |
12920 KB |
Output is correct |
17 |
Correct |
73 ms |
12920 KB |
Output is correct |
18 |
Correct |
53 ms |
12920 KB |
Output is correct |
19 |
Correct |
55 ms |
12924 KB |
Output is correct |
20 |
Correct |
5 ms |
2688 KB |
Output is correct |
21 |
Correct |
266 ms |
19704 KB |
Output is correct |
22 |
Correct |
236 ms |
19708 KB |
Output is correct |
23 |
Correct |
241 ms |
19704 KB |
Output is correct |
24 |
Correct |
233 ms |
19704 KB |
Output is correct |
25 |
Correct |
263 ms |
19724 KB |
Output is correct |
26 |
Correct |
242 ms |
19708 KB |
Output is correct |
27 |
Correct |
239 ms |
19704 KB |
Output is correct |
28 |
Correct |
129 ms |
19704 KB |
Output is correct |
29 |
Correct |
129 ms |
19704 KB |
Output is correct |
30 |
Correct |
6 ms |
2688 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
2688 KB |
Output is correct |
2 |
Correct |
205 ms |
36192 KB |
Output is correct |
3 |
Correct |
218 ms |
36216 KB |
Output is correct |
4 |
Correct |
228 ms |
36220 KB |
Output is correct |
5 |
Correct |
227 ms |
36216 KB |
Output is correct |
6 |
Correct |
231 ms |
36216 KB |
Output is correct |
7 |
Correct |
242 ms |
36216 KB |
Output is correct |
8 |
Correct |
229 ms |
36228 KB |
Output is correct |
9 |
Correct |
203 ms |
27128 KB |
Output is correct |
10 |
Correct |
210 ms |
27260 KB |
Output is correct |
11 |
Correct |
58 ms |
12664 KB |
Output is correct |
12 |
Correct |
55 ms |
12664 KB |
Output is correct |
13 |
Correct |
54 ms |
12664 KB |
Output is correct |
14 |
Correct |
54 ms |
12692 KB |
Output is correct |
15 |
Correct |
55 ms |
12664 KB |
Output is correct |
16 |
Correct |
55 ms |
12592 KB |
Output is correct |
17 |
Correct |
55 ms |
12664 KB |
Output is correct |
18 |
Correct |
47 ms |
12664 KB |
Output is correct |
19 |
Correct |
48 ms |
12664 KB |
Output is correct |
20 |
Correct |
5 ms |
2688 KB |
Output is correct |
21 |
Correct |
79 ms |
12884 KB |
Output is correct |
22 |
Correct |
77 ms |
12920 KB |
Output is correct |
23 |
Correct |
79 ms |
12920 KB |
Output is correct |
24 |
Correct |
72 ms |
12920 KB |
Output is correct |
25 |
Correct |
74 ms |
12920 KB |
Output is correct |
26 |
Correct |
73 ms |
12920 KB |
Output is correct |
27 |
Correct |
73 ms |
12920 KB |
Output is correct |
28 |
Correct |
53 ms |
12920 KB |
Output is correct |
29 |
Correct |
55 ms |
12924 KB |
Output is correct |
30 |
Correct |
5 ms |
2688 KB |
Output is correct |
31 |
Correct |
6 ms |
2816 KB |
Output is correct |
32 |
Correct |
6 ms |
2816 KB |
Output is correct |
33 |
Correct |
6 ms |
2816 KB |
Output is correct |
34 |
Correct |
6 ms |
2816 KB |
Output is correct |
35 |
Correct |
6 ms |
2816 KB |
Output is correct |
36 |
Correct |
6 ms |
2816 KB |
Output is correct |
37 |
Correct |
6 ms |
2816 KB |
Output is correct |
38 |
Correct |
6 ms |
2816 KB |
Output is correct |
39 |
Correct |
6 ms |
2816 KB |
Output is correct |
40 |
Correct |
5 ms |
2688 KB |
Output is correct |
41 |
Correct |
12 ms |
3840 KB |
Output is correct |
42 |
Correct |
13 ms |
3840 KB |
Output is correct |
43 |
Correct |
13 ms |
3840 KB |
Output is correct |
44 |
Correct |
13 ms |
3840 KB |
Output is correct |
45 |
Correct |
13 ms |
3840 KB |
Output is correct |
46 |
Correct |
14 ms |
3968 KB |
Output is correct |
47 |
Correct |
13 ms |
3840 KB |
Output is correct |
48 |
Correct |
11 ms |
3456 KB |
Output is correct |
49 |
Correct |
9 ms |
3072 KB |
Output is correct |
50 |
Correct |
6 ms |
2688 KB |
Output is correct |
51 |
Correct |
266 ms |
19704 KB |
Output is correct |
52 |
Correct |
236 ms |
19708 KB |
Output is correct |
53 |
Correct |
241 ms |
19704 KB |
Output is correct |
54 |
Correct |
233 ms |
19704 KB |
Output is correct |
55 |
Correct |
263 ms |
19724 KB |
Output is correct |
56 |
Correct |
242 ms |
19708 KB |
Output is correct |
57 |
Correct |
239 ms |
19704 KB |
Output is correct |
58 |
Correct |
129 ms |
19704 KB |
Output is correct |
59 |
Correct |
129 ms |
19704 KB |
Output is correct |
60 |
Correct |
6 ms |
2688 KB |
Output is correct |
61 |
Correct |
496 ms |
36172 KB |
Output is correct |
62 |
Correct |
564 ms |
36216 KB |
Output is correct |
63 |
Correct |
580 ms |
36216 KB |
Output is correct |
64 |
Correct |
526 ms |
36216 KB |
Output is correct |
65 |
Correct |
507 ms |
36172 KB |
Output is correct |
66 |
Correct |
503 ms |
36200 KB |
Output is correct |
67 |
Correct |
581 ms |
36168 KB |
Output is correct |
68 |
Correct |
418 ms |
27256 KB |
Output is correct |
69 |
Correct |
299 ms |
21972 KB |
Output is correct |
70 |
Correct |
6 ms |
2688 KB |
Output is correct |