#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef pair <ll,ll> pl;
typedef vector<pl> vpl;
#define s second
#define f first
int n;
struct FT
{
int n; vl dp;
FT (int n){
this->n = n;
dp.assign(n+1,0);
}
int lsb(int x){
return x & (-x);
}
ll query(int ind){
ll res=0;
while(ind){
res+=dp[ind];
ind-=lsb(ind);
}
return res;
}
void add(int ind, int value){
while(ind<=n){
dp[ind]+=value;
ind+=lsb(ind);
}
}
};
int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin>>n;
FT ft1(n),ft2(n);
ll a[n];
vpl aux(n);
for(int i=0; i<n; i++){
int x; cin>>x; aux[i]={x,i};
}
sort(aux.begin(),aux.end()); a[aux[0].s]=1; int temp=1;
for(int i=1; i<n; i++){
if(aux[i].f==aux[i-1].f) a[aux[i].s]=temp;
else temp++, a[aux[i].s]=temp;
}
//for(auto &x: a) cout<<x<<" "; cout<<endl;
ll mx=0;
for(int i=n-1; i>=0; i--){
mx=max(mx,a[i]);
ft1.add(a[i],1);
}
//cout<<query(mx-1,1)<<endl;
//int top=n+99;
ll ans=0;
for(int i=0; i<n; i++){
ft1.add(a[i],-1);
//cout<<query(a[i]-1,0)<<" "<<query(a[i]-1,1)<<endl;
ans+=ft1.query(a[i]-1)*(ft2.query(a[i]-1));
ft2.add(a[i],1);
}
cout<<ans<<endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
87 ms |
12052 KB |
Output is correct |
3 |
Correct |
98 ms |
11988 KB |
Output is correct |
4 |
Correct |
89 ms |
12060 KB |
Output is correct |
5 |
Correct |
89 ms |
12060 KB |
Output is correct |
6 |
Correct |
95 ms |
12048 KB |
Output is correct |
7 |
Correct |
85 ms |
11988 KB |
Output is correct |
8 |
Correct |
97 ms |
12052 KB |
Output is correct |
9 |
Correct |
93 ms |
11988 KB |
Output is correct |
10 |
Correct |
104 ms |
12052 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
117 ms |
12048 KB |
Output is correct |
2 |
Correct |
122 ms |
12048 KB |
Output is correct |
3 |
Correct |
136 ms |
11988 KB |
Output is correct |
4 |
Correct |
125 ms |
12052 KB |
Output is correct |
5 |
Correct |
123 ms |
12052 KB |
Output is correct |
6 |
Correct |
108 ms |
12052 KB |
Output is correct |
7 |
Correct |
125 ms |
12056 KB |
Output is correct |
8 |
Correct |
107 ms |
12056 KB |
Output is correct |
9 |
Correct |
130 ms |
12056 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
117 ms |
12048 KB |
Output is correct |
2 |
Correct |
122 ms |
12048 KB |
Output is correct |
3 |
Correct |
136 ms |
11988 KB |
Output is correct |
4 |
Correct |
125 ms |
12052 KB |
Output is correct |
5 |
Correct |
123 ms |
12052 KB |
Output is correct |
6 |
Correct |
108 ms |
12052 KB |
Output is correct |
7 |
Correct |
125 ms |
12056 KB |
Output is correct |
8 |
Correct |
107 ms |
12056 KB |
Output is correct |
9 |
Correct |
130 ms |
12056 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
116 ms |
12048 KB |
Output is correct |
12 |
Correct |
111 ms |
12052 KB |
Output is correct |
13 |
Correct |
128 ms |
11988 KB |
Output is correct |
14 |
Correct |
115 ms |
12056 KB |
Output is correct |
15 |
Correct |
116 ms |
11988 KB |
Output is correct |
16 |
Correct |
114 ms |
11988 KB |
Output is correct |
17 |
Correct |
121 ms |
12060 KB |
Output is correct |
18 |
Correct |
87 ms |
12048 KB |
Output is correct |
19 |
Correct |
89 ms |
11988 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
117 ms |
12048 KB |
Output is correct |
2 |
Correct |
122 ms |
12048 KB |
Output is correct |
3 |
Correct |
136 ms |
11988 KB |
Output is correct |
4 |
Correct |
125 ms |
12052 KB |
Output is correct |
5 |
Correct |
123 ms |
12052 KB |
Output is correct |
6 |
Correct |
108 ms |
12052 KB |
Output is correct |
7 |
Correct |
125 ms |
12056 KB |
Output is correct |
8 |
Correct |
107 ms |
12056 KB |
Output is correct |
9 |
Correct |
130 ms |
12056 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
116 ms |
12048 KB |
Output is correct |
12 |
Correct |
111 ms |
12052 KB |
Output is correct |
13 |
Correct |
128 ms |
11988 KB |
Output is correct |
14 |
Correct |
115 ms |
12056 KB |
Output is correct |
15 |
Correct |
116 ms |
11988 KB |
Output is correct |
16 |
Correct |
114 ms |
11988 KB |
Output is correct |
17 |
Correct |
121 ms |
12060 KB |
Output is correct |
18 |
Correct |
87 ms |
12048 KB |
Output is correct |
19 |
Correct |
89 ms |
11988 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
106 ms |
12048 KB |
Output is correct |
22 |
Correct |
101 ms |
12108 KB |
Output is correct |
23 |
Correct |
109 ms |
12052 KB |
Output is correct |
24 |
Correct |
98 ms |
12048 KB |
Output is correct |
25 |
Correct |
114 ms |
12048 KB |
Output is correct |
26 |
Correct |
112 ms |
12052 KB |
Output is correct |
27 |
Correct |
96 ms |
11988 KB |
Output is correct |
28 |
Correct |
71 ms |
11988 KB |
Output is correct |
29 |
Correct |
79 ms |
12044 KB |
Output is correct |
30 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
87 ms |
12052 KB |
Output is correct |
3 |
Correct |
98 ms |
11988 KB |
Output is correct |
4 |
Correct |
89 ms |
12060 KB |
Output is correct |
5 |
Correct |
89 ms |
12060 KB |
Output is correct |
6 |
Correct |
95 ms |
12048 KB |
Output is correct |
7 |
Correct |
85 ms |
11988 KB |
Output is correct |
8 |
Correct |
97 ms |
12052 KB |
Output is correct |
9 |
Correct |
93 ms |
11988 KB |
Output is correct |
10 |
Correct |
104 ms |
12052 KB |
Output is correct |
11 |
Correct |
117 ms |
12048 KB |
Output is correct |
12 |
Correct |
122 ms |
12048 KB |
Output is correct |
13 |
Correct |
136 ms |
11988 KB |
Output is correct |
14 |
Correct |
125 ms |
12052 KB |
Output is correct |
15 |
Correct |
123 ms |
12052 KB |
Output is correct |
16 |
Correct |
108 ms |
12052 KB |
Output is correct |
17 |
Correct |
125 ms |
12056 KB |
Output is correct |
18 |
Correct |
107 ms |
12056 KB |
Output is correct |
19 |
Correct |
130 ms |
12056 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
116 ms |
12048 KB |
Output is correct |
22 |
Correct |
111 ms |
12052 KB |
Output is correct |
23 |
Correct |
128 ms |
11988 KB |
Output is correct |
24 |
Correct |
115 ms |
12056 KB |
Output is correct |
25 |
Correct |
116 ms |
11988 KB |
Output is correct |
26 |
Correct |
114 ms |
11988 KB |
Output is correct |
27 |
Correct |
121 ms |
12060 KB |
Output is correct |
28 |
Correct |
87 ms |
12048 KB |
Output is correct |
29 |
Correct |
89 ms |
11988 KB |
Output is correct |
30 |
Correct |
0 ms |
212 KB |
Output is correct |
31 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
32 |
Halted |
0 ms |
0 KB |
- |