#include <bits/stdc++.h>
#include <string>
#define ll long long
#define pb push_back
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
map<ll,ll>m;
ll ans;
const ll maxn=3e5+100;
ll n,a[maxn];
ll tr[maxn],lft[maxn];
ll cnt=1;
ll sum(ll id){
ll ret=0;
for(;id;id-=id&(-id))ret+=tr[id];
return ret;
}
void add(ll id){
for(;id<=cnt;id+=id&(-id))tr[id]++;
}
ll qur(ll l,ll r){
if(r==0)return 0;
return sum(r)-sum(l-1);
}
int main()
{
IOS
cin>>n;
for(ll i=0;i<n;i++){
cin>>a[i];
m[a[i]]=1;
}
for(auto &x:m){
x.second=cnt++;
}
for(ll i=0;i<n;i++){
a[i]=m[a[i]];
//cout<<a[i]<<' ';
}
cnt--;
for(ll i=0;i<n;i++){
lft[i]=qur(1,a[i]-1);
add(a[i]);
//cout<<lft[i]<<' ';
}
for(ll i=0;i<n;i++){
ll righ=qur(1,a[i]-1)-lft[i];
ans+=righ*lft[i];
}
cout<<ans<<endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
220 ms |
26104 KB |
Output is correct |
3 |
Correct |
226 ms |
26136 KB |
Output is correct |
4 |
Correct |
218 ms |
26104 KB |
Output is correct |
5 |
Correct |
220 ms |
26104 KB |
Output is correct |
6 |
Correct |
221 ms |
26104 KB |
Output is correct |
7 |
Correct |
221 ms |
26232 KB |
Output is correct |
8 |
Correct |
220 ms |
26104 KB |
Output is correct |
9 |
Correct |
182 ms |
15992 KB |
Output is correct |
10 |
Correct |
182 ms |
15992 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
36 ms |
4988 KB |
Output is correct |
2 |
Correct |
34 ms |
5112 KB |
Output is correct |
3 |
Correct |
37 ms |
5016 KB |
Output is correct |
4 |
Correct |
34 ms |
4984 KB |
Output is correct |
5 |
Correct |
33 ms |
4984 KB |
Output is correct |
6 |
Correct |
33 ms |
4984 KB |
Output is correct |
7 |
Correct |
32 ms |
4984 KB |
Output is correct |
8 |
Correct |
26 ms |
4984 KB |
Output is correct |
9 |
Correct |
32 ms |
4984 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
36 ms |
4988 KB |
Output is correct |
2 |
Correct |
34 ms |
5112 KB |
Output is correct |
3 |
Correct |
37 ms |
5016 KB |
Output is correct |
4 |
Correct |
34 ms |
4984 KB |
Output is correct |
5 |
Correct |
33 ms |
4984 KB |
Output is correct |
6 |
Correct |
33 ms |
4984 KB |
Output is correct |
7 |
Correct |
32 ms |
4984 KB |
Output is correct |
8 |
Correct |
26 ms |
4984 KB |
Output is correct |
9 |
Correct |
32 ms |
4984 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
11 |
Correct |
66 ms |
4988 KB |
Output is correct |
12 |
Correct |
62 ms |
4984 KB |
Output is correct |
13 |
Correct |
60 ms |
4984 KB |
Output is correct |
14 |
Correct |
61 ms |
5048 KB |
Output is correct |
15 |
Correct |
62 ms |
4984 KB |
Output is correct |
16 |
Correct |
61 ms |
4984 KB |
Output is correct |
17 |
Correct |
62 ms |
5112 KB |
Output is correct |
18 |
Correct |
37 ms |
4984 KB |
Output is correct |
19 |
Correct |
34 ms |
5112 KB |
Output is correct |
20 |
Correct |
5 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
376 KB |
Output is correct |
9 |
Correct |
5 ms |
376 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
376 KB |
Output is correct |
9 |
Correct |
5 ms |
376 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
11 |
Correct |
11 ms |
1144 KB |
Output is correct |
12 |
Correct |
12 ms |
1272 KB |
Output is correct |
13 |
Correct |
12 ms |
1272 KB |
Output is correct |
14 |
Correct |
12 ms |
1272 KB |
Output is correct |
15 |
Correct |
11 ms |
1144 KB |
Output is correct |
16 |
Correct |
11 ms |
1148 KB |
Output is correct |
17 |
Correct |
11 ms |
1144 KB |
Output is correct |
18 |
Correct |
10 ms |
760 KB |
Output is correct |
19 |
Correct |
7 ms |
504 KB |
Output is correct |
20 |
Correct |
4 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
36 ms |
4988 KB |
Output is correct |
2 |
Correct |
34 ms |
5112 KB |
Output is correct |
3 |
Correct |
37 ms |
5016 KB |
Output is correct |
4 |
Correct |
34 ms |
4984 KB |
Output is correct |
5 |
Correct |
33 ms |
4984 KB |
Output is correct |
6 |
Correct |
33 ms |
4984 KB |
Output is correct |
7 |
Correct |
32 ms |
4984 KB |
Output is correct |
8 |
Correct |
26 ms |
4984 KB |
Output is correct |
9 |
Correct |
32 ms |
4984 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
11 |
Correct |
66 ms |
4988 KB |
Output is correct |
12 |
Correct |
62 ms |
4984 KB |
Output is correct |
13 |
Correct |
60 ms |
4984 KB |
Output is correct |
14 |
Correct |
61 ms |
5048 KB |
Output is correct |
15 |
Correct |
62 ms |
4984 KB |
Output is correct |
16 |
Correct |
61 ms |
4984 KB |
Output is correct |
17 |
Correct |
62 ms |
5112 KB |
Output is correct |
18 |
Correct |
37 ms |
4984 KB |
Output is correct |
19 |
Correct |
34 ms |
5112 KB |
Output is correct |
20 |
Correct |
5 ms |
376 KB |
Output is correct |
21 |
Correct |
284 ms |
11768 KB |
Output is correct |
22 |
Correct |
270 ms |
11768 KB |
Output is correct |
23 |
Correct |
298 ms |
11696 KB |
Output is correct |
24 |
Correct |
265 ms |
11768 KB |
Output is correct |
25 |
Correct |
271 ms |
11768 KB |
Output is correct |
26 |
Correct |
298 ms |
11768 KB |
Output is correct |
27 |
Correct |
261 ms |
11772 KB |
Output is correct |
28 |
Correct |
127 ms |
11768 KB |
Output is correct |
29 |
Correct |
126 ms |
11768 KB |
Output is correct |
30 |
Correct |
5 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
220 ms |
26104 KB |
Output is correct |
3 |
Correct |
226 ms |
26136 KB |
Output is correct |
4 |
Correct |
218 ms |
26104 KB |
Output is correct |
5 |
Correct |
220 ms |
26104 KB |
Output is correct |
6 |
Correct |
221 ms |
26104 KB |
Output is correct |
7 |
Correct |
221 ms |
26232 KB |
Output is correct |
8 |
Correct |
220 ms |
26104 KB |
Output is correct |
9 |
Correct |
182 ms |
15992 KB |
Output is correct |
10 |
Correct |
182 ms |
15992 KB |
Output is correct |
11 |
Correct |
36 ms |
4988 KB |
Output is correct |
12 |
Correct |
34 ms |
5112 KB |
Output is correct |
13 |
Correct |
37 ms |
5016 KB |
Output is correct |
14 |
Correct |
34 ms |
4984 KB |
Output is correct |
15 |
Correct |
33 ms |
4984 KB |
Output is correct |
16 |
Correct |
33 ms |
4984 KB |
Output is correct |
17 |
Correct |
32 ms |
4984 KB |
Output is correct |
18 |
Correct |
26 ms |
4984 KB |
Output is correct |
19 |
Correct |
32 ms |
4984 KB |
Output is correct |
20 |
Correct |
5 ms |
376 KB |
Output is correct |
21 |
Correct |
66 ms |
4988 KB |
Output is correct |
22 |
Correct |
62 ms |
4984 KB |
Output is correct |
23 |
Correct |
60 ms |
4984 KB |
Output is correct |
24 |
Correct |
61 ms |
5048 KB |
Output is correct |
25 |
Correct |
62 ms |
4984 KB |
Output is correct |
26 |
Correct |
61 ms |
4984 KB |
Output is correct |
27 |
Correct |
62 ms |
5112 KB |
Output is correct |
28 |
Correct |
37 ms |
4984 KB |
Output is correct |
29 |
Correct |
34 ms |
5112 KB |
Output is correct |
30 |
Correct |
5 ms |
376 KB |
Output is correct |
31 |
Correct |
5 ms |
376 KB |
Output is correct |
32 |
Correct |
5 ms |
376 KB |
Output is correct |
33 |
Correct |
5 ms |
376 KB |
Output is correct |
34 |
Correct |
5 ms |
376 KB |
Output is correct |
35 |
Correct |
5 ms |
376 KB |
Output is correct |
36 |
Correct |
5 ms |
376 KB |
Output is correct |
37 |
Correct |
5 ms |
376 KB |
Output is correct |
38 |
Correct |
5 ms |
376 KB |
Output is correct |
39 |
Correct |
5 ms |
376 KB |
Output is correct |
40 |
Correct |
5 ms |
376 KB |
Output is correct |
41 |
Correct |
11 ms |
1144 KB |
Output is correct |
42 |
Correct |
12 ms |
1272 KB |
Output is correct |
43 |
Correct |
12 ms |
1272 KB |
Output is correct |
44 |
Correct |
12 ms |
1272 KB |
Output is correct |
45 |
Correct |
11 ms |
1144 KB |
Output is correct |
46 |
Correct |
11 ms |
1148 KB |
Output is correct |
47 |
Correct |
11 ms |
1144 KB |
Output is correct |
48 |
Correct |
10 ms |
760 KB |
Output is correct |
49 |
Correct |
7 ms |
504 KB |
Output is correct |
50 |
Correct |
4 ms |
376 KB |
Output is correct |
51 |
Correct |
284 ms |
11768 KB |
Output is correct |
52 |
Correct |
270 ms |
11768 KB |
Output is correct |
53 |
Correct |
298 ms |
11696 KB |
Output is correct |
54 |
Correct |
265 ms |
11768 KB |
Output is correct |
55 |
Correct |
271 ms |
11768 KB |
Output is correct |
56 |
Correct |
298 ms |
11768 KB |
Output is correct |
57 |
Correct |
261 ms |
11772 KB |
Output is correct |
58 |
Correct |
127 ms |
11768 KB |
Output is correct |
59 |
Correct |
126 ms |
11768 KB |
Output is correct |
60 |
Correct |
5 ms |
376 KB |
Output is correct |
61 |
Correct |
541 ms |
26104 KB |
Output is correct |
62 |
Correct |
560 ms |
26104 KB |
Output is correct |
63 |
Correct |
547 ms |
26104 KB |
Output is correct |
64 |
Correct |
537 ms |
26232 KB |
Output is correct |
65 |
Correct |
539 ms |
26104 KB |
Output is correct |
66 |
Correct |
548 ms |
26104 KB |
Output is correct |
67 |
Correct |
548 ms |
26104 KB |
Output is correct |
68 |
Correct |
424 ms |
15992 KB |
Output is correct |
69 |
Correct |
342 ms |
14200 KB |
Output is correct |
70 |
Correct |
5 ms |
376 KB |
Output is correct |