#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for (int i=a;i<=b;i++)
#define rep2(i,a,b,c) for (int i=a;i<=b;i+=c)
#define rev(i,a,b) for (int i=a;i>=b;i--)
#define rev2(i,a,b,c) for (int i=a;i>=b;i-=c)
#define ii pair<int,int>
#define bit(i,j) ((i>>j)&1)
#define ull unsigned long long
#define pb push_back
#define ll long long
#define int long long
#define F first
#define S second
const int N=1e5+5;
const int mod=1e9+7;
const int MAX=1e9;
int n,res,a[N],dp[N],s[N*4],dem[N];
vector<int> uni;
void update(int id,int l,int r,int i,int val)
{
if(i>r||i<l)
return;
if(l==r)
{
s[id]=val;
return;
}
int mid=(l+r)/2;
update(id*2,l,mid,i,val);
update(id*2+1,mid+1,r,i,val);
s[id]=s[id*2]+s[id*2+1];
}
int get(int id,int l,int r,int u,int v)
{
if(v<l||r<u)
return 0;
if(l>=u&&r<=v)
{
return s[id];
}
int mid=(l+r)/2;
return get(id*2,l,mid,u,v)+get(id*2+1,mid+1,r,u,v);
}
void solution()
{
cin>>n;
rep(i,1,n)
{
cin>>a[i];
uni.push_back(a[i]);
}
sort(uni.begin(),uni.end());
uni.resize(unique(uni.begin(),uni.end())-uni.begin());
rep(i,1,n) a[i]=lower_bound(uni.begin(),uni.end(),a[i])-uni.begin()+1;
rep(i,1,n)
{
dp[i]=get(1,1,n,0,a[i]-1);
update(1,1,n,a[i],1);
}
memset(s,0,sizeof(s));
rev(i,n,1){
res+=dp[i]*get(1,1,n,0,a[i]-1);
update(1,1,n,a[i],1);
}
cout<<res;
}
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int test=1;
// cin>>test;
while(test--)
solution();
}
/*
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
3420 KB |
Output is correct |
2 |
Runtime error |
13 ms |
6056 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
7 ms |
5592 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
7 ms |
5592 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
3416 KB |
Output is correct |
2 |
Correct |
2 ms |
3420 KB |
Output is correct |
3 |
Correct |
1 ms |
3420 KB |
Output is correct |
4 |
Correct |
2 ms |
3420 KB |
Output is correct |
5 |
Correct |
2 ms |
3416 KB |
Output is correct |
6 |
Correct |
2 ms |
3416 KB |
Output is correct |
7 |
Correct |
2 ms |
3420 KB |
Output is correct |
8 |
Incorrect |
2 ms |
3420 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
3416 KB |
Output is correct |
2 |
Correct |
2 ms |
3420 KB |
Output is correct |
3 |
Correct |
1 ms |
3420 KB |
Output is correct |
4 |
Correct |
2 ms |
3420 KB |
Output is correct |
5 |
Correct |
2 ms |
3416 KB |
Output is correct |
6 |
Correct |
2 ms |
3416 KB |
Output is correct |
7 |
Correct |
2 ms |
3420 KB |
Output is correct |
8 |
Incorrect |
2 ms |
3420 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
7 ms |
5592 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
3420 KB |
Output is correct |
2 |
Runtime error |
13 ms |
6056 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |