#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mx=3e5+10;
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+=r[i]*l[i];
}cout<<ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
4972 KB |
Output is correct |
2 |
Correct |
508 ms |
29676 KB |
Output is correct |
3 |
Correct |
509 ms |
29676 KB |
Output is correct |
4 |
Correct |
511 ms |
29804 KB |
Output is correct |
5 |
Correct |
510 ms |
29548 KB |
Output is correct |
6 |
Correct |
512 ms |
29596 KB |
Output is correct |
7 |
Correct |
519 ms |
29548 KB |
Output is correct |
8 |
Correct |
511 ms |
29420 KB |
Output is correct |
9 |
Correct |
477 ms |
20248 KB |
Output is correct |
10 |
Correct |
472 ms |
20204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
177 ms |
10348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
177 ms |
10348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
5100 KB |
Output is correct |
2 |
Correct |
5 ms |
5248 KB |
Output is correct |
3 |
Correct |
4 ms |
5100 KB |
Output is correct |
4 |
Correct |
5 ms |
5100 KB |
Output is correct |
5 |
Correct |
4 ms |
5100 KB |
Output is correct |
6 |
Correct |
4 ms |
5100 KB |
Output is correct |
7 |
Correct |
4 ms |
5100 KB |
Output is correct |
8 |
Correct |
4 ms |
5100 KB |
Output is correct |
9 |
Correct |
4 ms |
5100 KB |
Output is correct |
10 |
Correct |
4 ms |
4972 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
5100 KB |
Output is correct |
2 |
Correct |
5 ms |
5248 KB |
Output is correct |
3 |
Correct |
4 ms |
5100 KB |
Output is correct |
4 |
Correct |
5 ms |
5100 KB |
Output is correct |
5 |
Correct |
4 ms |
5100 KB |
Output is correct |
6 |
Correct |
4 ms |
5100 KB |
Output is correct |
7 |
Correct |
4 ms |
5100 KB |
Output is correct |
8 |
Correct |
4 ms |
5100 KB |
Output is correct |
9 |
Correct |
4 ms |
5100 KB |
Output is correct |
10 |
Correct |
4 ms |
4972 KB |
Output is correct |
11 |
Correct |
30 ms |
5996 KB |
Output is correct |
12 |
Correct |
30 ms |
5996 KB |
Output is correct |
13 |
Correct |
23 ms |
5996 KB |
Output is correct |
14 |
Correct |
23 ms |
5996 KB |
Output is correct |
15 |
Correct |
23 ms |
5996 KB |
Output is correct |
16 |
Correct |
23 ms |
6124 KB |
Output is correct |
17 |
Correct |
23 ms |
5996 KB |
Output is correct |
18 |
Correct |
25 ms |
5612 KB |
Output is correct |
19 |
Correct |
14 ms |
5228 KB |
Output is correct |
20 |
Correct |
4 ms |
4972 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
177 ms |
10348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
4972 KB |
Output is correct |
2 |
Correct |
508 ms |
29676 KB |
Output is correct |
3 |
Correct |
509 ms |
29676 KB |
Output is correct |
4 |
Correct |
511 ms |
29804 KB |
Output is correct |
5 |
Correct |
510 ms |
29548 KB |
Output is correct |
6 |
Correct |
512 ms |
29596 KB |
Output is correct |
7 |
Correct |
519 ms |
29548 KB |
Output is correct |
8 |
Correct |
511 ms |
29420 KB |
Output is correct |
9 |
Correct |
477 ms |
20248 KB |
Output is correct |
10 |
Correct |
472 ms |
20204 KB |
Output is correct |
11 |
Incorrect |
177 ms |
10348 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |