#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mx=4e5+20;
const int mod= 1e9+7 ;
const ll inf=1e9+5;
//***while there is life there is hope
int n;
int arr[mx*4];
map<ll,int>mp;
void compres(){
int cnt=0;
for(auto &it:mp){
//cout<<it.first;
it.second=cnt;
cnt++;
}
}
void update(int node,int st,int en,int pos){
if(st==en){
arr[node]++;
return;
}
int mid=(st+en)/2;
if(pos<=mid){
update(node*2,st,mid,pos);
}else{
update(node*2+1,mid+1,en,pos);
}
arr[node]=arr[node*2]+arr[node*2+1];
return ;
}
int query(int node,int st,int en,int l,int r){
if(st>r||en<l){return 0;}
if(st>=l&&en<=r){return arr[node];}
int mid=(st+en)/2;
return query(node*2,st,mid,l,r)+query(node*2+1,mid+1,en,l,r);
}
int l[mx];int r[mx];
int main() {
cin>>n;
vector<ll>v(n);
for(int i=0;i<n;i++){
cin>>v[i];
mp[v[i]];
}
compres();
for(int i=0;i<n;i++){
v[i]=mp[v[i]];
// cout<<v[i];
}
for(int i=0;i<n;i++){
l[i]=query(1,0,mx,0,v[i]-1);
// cout<<l[i]<<" ";
update(1,0,mx,v[i]);
}
memset(arr,0,sizeof(arr));ll ans=0;
for(int i=n-1;i>=0;i--){
r[i]=query(1,0,mx,0,v[i]-1);
//cout<<r[i]<<" ";
update(1,0,mx,v[i]);
ans+=1LL*r[i]*l[i];
}cout<<ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
6636 KB |
Output is correct |
2 |
Correct |
536 ms |
34040 KB |
Output is correct |
3 |
Correct |
514 ms |
34176 KB |
Output is correct |
4 |
Correct |
530 ms |
34032 KB |
Output is correct |
5 |
Correct |
517 ms |
34028 KB |
Output is correct |
6 |
Correct |
530 ms |
34028 KB |
Output is correct |
7 |
Correct |
514 ms |
34052 KB |
Output is correct |
8 |
Correct |
510 ms |
33644 KB |
Output is correct |
9 |
Correct |
481 ms |
24556 KB |
Output is correct |
10 |
Correct |
481 ms |
24684 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
190 ms |
11836 KB |
Output is correct |
2 |
Correct |
182 ms |
11884 KB |
Output is correct |
3 |
Correct |
181 ms |
12012 KB |
Output is correct |
4 |
Correct |
181 ms |
11884 KB |
Output is correct |
5 |
Correct |
188 ms |
11884 KB |
Output is correct |
6 |
Correct |
180 ms |
11884 KB |
Output is correct |
7 |
Correct |
180 ms |
12012 KB |
Output is correct |
8 |
Correct |
173 ms |
12012 KB |
Output is correct |
9 |
Correct |
172 ms |
11904 KB |
Output is correct |
10 |
Correct |
4 ms |
6636 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
190 ms |
11836 KB |
Output is correct |
2 |
Correct |
182 ms |
11884 KB |
Output is correct |
3 |
Correct |
181 ms |
12012 KB |
Output is correct |
4 |
Correct |
181 ms |
11884 KB |
Output is correct |
5 |
Correct |
188 ms |
11884 KB |
Output is correct |
6 |
Correct |
180 ms |
11884 KB |
Output is correct |
7 |
Correct |
180 ms |
12012 KB |
Output is correct |
8 |
Correct |
173 ms |
12012 KB |
Output is correct |
9 |
Correct |
172 ms |
11904 KB |
Output is correct |
10 |
Correct |
4 ms |
6636 KB |
Output is correct |
11 |
Correct |
275 ms |
12140 KB |
Output is correct |
12 |
Correct |
272 ms |
12268 KB |
Output is correct |
13 |
Correct |
270 ms |
12140 KB |
Output is correct |
14 |
Correct |
274 ms |
12416 KB |
Output is correct |
15 |
Correct |
270 ms |
12140 KB |
Output is correct |
16 |
Correct |
269 ms |
12140 KB |
Output is correct |
17 |
Correct |
274 ms |
12268 KB |
Output is correct |
18 |
Correct |
218 ms |
12268 KB |
Output is correct |
19 |
Correct |
210 ms |
12192 KB |
Output is correct |
20 |
Correct |
4 ms |
6636 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
6636 KB |
Output is correct |
2 |
Correct |
6 ms |
6636 KB |
Output is correct |
3 |
Correct |
5 ms |
6636 KB |
Output is correct |
4 |
Correct |
5 ms |
6636 KB |
Output is correct |
5 |
Correct |
5 ms |
6636 KB |
Output is correct |
6 |
Correct |
5 ms |
6636 KB |
Output is correct |
7 |
Correct |
5 ms |
6636 KB |
Output is correct |
8 |
Correct |
5 ms |
6636 KB |
Output is correct |
9 |
Correct |
5 ms |
6636 KB |
Output is correct |
10 |
Correct |
4 ms |
6636 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
6636 KB |
Output is correct |
2 |
Correct |
6 ms |
6636 KB |
Output is correct |
3 |
Correct |
5 ms |
6636 KB |
Output is correct |
4 |
Correct |
5 ms |
6636 KB |
Output is correct |
5 |
Correct |
5 ms |
6636 KB |
Output is correct |
6 |
Correct |
5 ms |
6636 KB |
Output is correct |
7 |
Correct |
5 ms |
6636 KB |
Output is correct |
8 |
Correct |
5 ms |
6636 KB |
Output is correct |
9 |
Correct |
5 ms |
6636 KB |
Output is correct |
10 |
Correct |
4 ms |
6636 KB |
Output is correct |
11 |
Correct |
24 ms |
7532 KB |
Output is correct |
12 |
Correct |
24 ms |
7532 KB |
Output is correct |
13 |
Correct |
24 ms |
7532 KB |
Output is correct |
14 |
Correct |
24 ms |
7532 KB |
Output is correct |
15 |
Correct |
24 ms |
7532 KB |
Output is correct |
16 |
Correct |
25 ms |
7532 KB |
Output is correct |
17 |
Correct |
24 ms |
7532 KB |
Output is correct |
18 |
Correct |
22 ms |
7148 KB |
Output is correct |
19 |
Correct |
15 ms |
6764 KB |
Output is correct |
20 |
Correct |
5 ms |
6636 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
190 ms |
11836 KB |
Output is correct |
2 |
Correct |
182 ms |
11884 KB |
Output is correct |
3 |
Correct |
181 ms |
12012 KB |
Output is correct |
4 |
Correct |
181 ms |
11884 KB |
Output is correct |
5 |
Correct |
188 ms |
11884 KB |
Output is correct |
6 |
Correct |
180 ms |
11884 KB |
Output is correct |
7 |
Correct |
180 ms |
12012 KB |
Output is correct |
8 |
Correct |
173 ms |
12012 KB |
Output is correct |
9 |
Correct |
172 ms |
11904 KB |
Output is correct |
10 |
Correct |
4 ms |
6636 KB |
Output is correct |
11 |
Correct |
275 ms |
12140 KB |
Output is correct |
12 |
Correct |
272 ms |
12268 KB |
Output is correct |
13 |
Correct |
270 ms |
12140 KB |
Output is correct |
14 |
Correct |
274 ms |
12416 KB |
Output is correct |
15 |
Correct |
270 ms |
12140 KB |
Output is correct |
16 |
Correct |
269 ms |
12140 KB |
Output is correct |
17 |
Correct |
274 ms |
12268 KB |
Output is correct |
18 |
Correct |
218 ms |
12268 KB |
Output is correct |
19 |
Correct |
210 ms |
12192 KB |
Output is correct |
20 |
Correct |
4 ms |
6636 KB |
Output is correct |
21 |
Correct |
588 ms |
19052 KB |
Output is correct |
22 |
Correct |
605 ms |
19052 KB |
Output is correct |
23 |
Correct |
573 ms |
18924 KB |
Output is correct |
24 |
Correct |
608 ms |
19032 KB |
Output is correct |
25 |
Correct |
606 ms |
18924 KB |
Output is correct |
26 |
Correct |
569 ms |
19052 KB |
Output is correct |
27 |
Correct |
576 ms |
18924 KB |
Output is correct |
28 |
Correct |
327 ms |
19052 KB |
Output is correct |
29 |
Correct |
329 ms |
18924 KB |
Output is correct |
30 |
Correct |
4 ms |
6636 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
6636 KB |
Output is correct |
2 |
Correct |
536 ms |
34040 KB |
Output is correct |
3 |
Correct |
514 ms |
34176 KB |
Output is correct |
4 |
Correct |
530 ms |
34032 KB |
Output is correct |
5 |
Correct |
517 ms |
34028 KB |
Output is correct |
6 |
Correct |
530 ms |
34028 KB |
Output is correct |
7 |
Correct |
514 ms |
34052 KB |
Output is correct |
8 |
Correct |
510 ms |
33644 KB |
Output is correct |
9 |
Correct |
481 ms |
24556 KB |
Output is correct |
10 |
Correct |
481 ms |
24684 KB |
Output is correct |
11 |
Correct |
190 ms |
11836 KB |
Output is correct |
12 |
Correct |
182 ms |
11884 KB |
Output is correct |
13 |
Correct |
181 ms |
12012 KB |
Output is correct |
14 |
Correct |
181 ms |
11884 KB |
Output is correct |
15 |
Correct |
188 ms |
11884 KB |
Output is correct |
16 |
Correct |
180 ms |
11884 KB |
Output is correct |
17 |
Correct |
180 ms |
12012 KB |
Output is correct |
18 |
Correct |
173 ms |
12012 KB |
Output is correct |
19 |
Correct |
172 ms |
11904 KB |
Output is correct |
20 |
Correct |
4 ms |
6636 KB |
Output is correct |
21 |
Correct |
275 ms |
12140 KB |
Output is correct |
22 |
Correct |
272 ms |
12268 KB |
Output is correct |
23 |
Correct |
270 ms |
12140 KB |
Output is correct |
24 |
Correct |
274 ms |
12416 KB |
Output is correct |
25 |
Correct |
270 ms |
12140 KB |
Output is correct |
26 |
Correct |
269 ms |
12140 KB |
Output is correct |
27 |
Correct |
274 ms |
12268 KB |
Output is correct |
28 |
Correct |
218 ms |
12268 KB |
Output is correct |
29 |
Correct |
210 ms |
12192 KB |
Output is correct |
30 |
Correct |
4 ms |
6636 KB |
Output is correct |
31 |
Correct |
5 ms |
6636 KB |
Output is correct |
32 |
Correct |
6 ms |
6636 KB |
Output is correct |
33 |
Correct |
5 ms |
6636 KB |
Output is correct |
34 |
Correct |
5 ms |
6636 KB |
Output is correct |
35 |
Correct |
5 ms |
6636 KB |
Output is correct |
36 |
Correct |
5 ms |
6636 KB |
Output is correct |
37 |
Correct |
5 ms |
6636 KB |
Output is correct |
38 |
Correct |
5 ms |
6636 KB |
Output is correct |
39 |
Correct |
5 ms |
6636 KB |
Output is correct |
40 |
Correct |
4 ms |
6636 KB |
Output is correct |
41 |
Correct |
24 ms |
7532 KB |
Output is correct |
42 |
Correct |
24 ms |
7532 KB |
Output is correct |
43 |
Correct |
24 ms |
7532 KB |
Output is correct |
44 |
Correct |
24 ms |
7532 KB |
Output is correct |
45 |
Correct |
24 ms |
7532 KB |
Output is correct |
46 |
Correct |
25 ms |
7532 KB |
Output is correct |
47 |
Correct |
24 ms |
7532 KB |
Output is correct |
48 |
Correct |
22 ms |
7148 KB |
Output is correct |
49 |
Correct |
15 ms |
6764 KB |
Output is correct |
50 |
Correct |
5 ms |
6636 KB |
Output is correct |
51 |
Correct |
588 ms |
19052 KB |
Output is correct |
52 |
Correct |
605 ms |
19052 KB |
Output is correct |
53 |
Correct |
573 ms |
18924 KB |
Output is correct |
54 |
Correct |
608 ms |
19032 KB |
Output is correct |
55 |
Correct |
606 ms |
18924 KB |
Output is correct |
56 |
Correct |
569 ms |
19052 KB |
Output is correct |
57 |
Correct |
576 ms |
18924 KB |
Output is correct |
58 |
Correct |
327 ms |
19052 KB |
Output is correct |
59 |
Correct |
329 ms |
18924 KB |
Output is correct |
60 |
Correct |
4 ms |
6636 KB |
Output is correct |
61 |
Correct |
992 ms |
35740 KB |
Output is correct |
62 |
Correct |
1000 ms |
35564 KB |
Output is correct |
63 |
Correct |
972 ms |
35564 KB |
Output is correct |
64 |
Correct |
1022 ms |
35692 KB |
Output is correct |
65 |
Correct |
970 ms |
35644 KB |
Output is correct |
66 |
Correct |
973 ms |
35820 KB |
Output is correct |
67 |
Correct |
1006 ms |
35820 KB |
Output is correct |
68 |
Correct |
796 ms |
26604 KB |
Output is correct |
69 |
Correct |
649 ms |
21228 KB |
Output is correct |
70 |
Correct |
4 ms |
6636 KB |
Output is correct |