#include<bits/stdc++.h>
#define pb push_back
#define ll long long
#define f first
#define s second
#define sz(x) (int)x.size()
#define pii pair<ll,ll>
using namespace std;
const int N=3e5+5;
int fw[N]{0};
void add(int i){
for(;i<N;i+=i&-i)fw[i]++;
}
int qr(int i,int res=0){
for(;i;i-=i&-i)res+=fw[i];
return res;
}
int main(){
ios_base::sync_with_stdio(false);cin.tie(NULL);
int n;cin>>n;vector<ll>b;
ll a[n+1];for(int i=1;i<=n;i++)cin>>a[i],b.pb(a[i]);
sort(b.begin(),b.end());b.erase(unique(b.begin(),b.end()),b.end());
ll tt[n+1];
for(int i=1;i<=n;i++){
int idx=lower_bound(b.begin(),b.end(),a[i])-b.begin();
tt[i] = qr(idx);add(idx+1);
}ll ans=0;
for(int i=1;i<=n;i++)fw[i]=0;
for(int i=n;i>=1;i--){
int idx=lower_bound(b.begin(),b.end(),a[i])-b.begin();
tt[i] *= qr(idx);add(idx+1);ans+=tt[i];
}cout<<ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
86 ms |
15696 KB |
Output is correct |
3 |
Correct |
98 ms |
15076 KB |
Output is correct |
4 |
Correct |
88 ms |
15488 KB |
Output is correct |
5 |
Correct |
89 ms |
15312 KB |
Output is correct |
6 |
Correct |
94 ms |
15784 KB |
Output is correct |
7 |
Correct |
85 ms |
14812 KB |
Output is correct |
8 |
Correct |
94 ms |
15292 KB |
Output is correct |
9 |
Correct |
83 ms |
15720 KB |
Output is correct |
10 |
Correct |
81 ms |
15360 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
42 ms |
9420 KB |
Output is correct |
2 |
Correct |
43 ms |
10176 KB |
Output is correct |
3 |
Correct |
42 ms |
9268 KB |
Output is correct |
4 |
Correct |
43 ms |
10436 KB |
Output is correct |
5 |
Correct |
42 ms |
9516 KB |
Output is correct |
6 |
Correct |
41 ms |
9680 KB |
Output is correct |
7 |
Correct |
44 ms |
10720 KB |
Output is correct |
8 |
Correct |
40 ms |
9156 KB |
Output is correct |
9 |
Correct |
41 ms |
10692 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
42 ms |
9420 KB |
Output is correct |
2 |
Correct |
43 ms |
10176 KB |
Output is correct |
3 |
Correct |
42 ms |
9268 KB |
Output is correct |
4 |
Correct |
43 ms |
10436 KB |
Output is correct |
5 |
Correct |
42 ms |
9516 KB |
Output is correct |
6 |
Correct |
41 ms |
9680 KB |
Output is correct |
7 |
Correct |
44 ms |
10720 KB |
Output is correct |
8 |
Correct |
40 ms |
9156 KB |
Output is correct |
9 |
Correct |
41 ms |
10692 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
61 ms |
10744 KB |
Output is correct |
12 |
Correct |
60 ms |
9572 KB |
Output is correct |
13 |
Correct |
65 ms |
9564 KB |
Output is correct |
14 |
Correct |
60 ms |
10124 KB |
Output is correct |
15 |
Correct |
70 ms |
9472 KB |
Output is correct |
16 |
Correct |
67 ms |
10924 KB |
Output is correct |
17 |
Correct |
67 ms |
10992 KB |
Output is correct |
18 |
Correct |
38 ms |
10560 KB |
Output is correct |
19 |
Correct |
38 ms |
10716 KB |
Output is correct |
20 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
600 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
600 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
5 ms |
860 KB |
Output is correct |
12 |
Correct |
5 ms |
856 KB |
Output is correct |
13 |
Correct |
5 ms |
860 KB |
Output is correct |
14 |
Correct |
4 ms |
988 KB |
Output is correct |
15 |
Correct |
5 ms |
864 KB |
Output is correct |
16 |
Correct |
5 ms |
860 KB |
Output is correct |
17 |
Correct |
5 ms |
856 KB |
Output is correct |
18 |
Correct |
6 ms |
860 KB |
Output is correct |
19 |
Correct |
3 ms |
932 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
42 ms |
9420 KB |
Output is correct |
2 |
Correct |
43 ms |
10176 KB |
Output is correct |
3 |
Correct |
42 ms |
9268 KB |
Output is correct |
4 |
Correct |
43 ms |
10436 KB |
Output is correct |
5 |
Correct |
42 ms |
9516 KB |
Output is correct |
6 |
Correct |
41 ms |
9680 KB |
Output is correct |
7 |
Correct |
44 ms |
10720 KB |
Output is correct |
8 |
Correct |
40 ms |
9156 KB |
Output is correct |
9 |
Correct |
41 ms |
10692 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
61 ms |
10744 KB |
Output is correct |
12 |
Correct |
60 ms |
9572 KB |
Output is correct |
13 |
Correct |
65 ms |
9564 KB |
Output is correct |
14 |
Correct |
60 ms |
10124 KB |
Output is correct |
15 |
Correct |
70 ms |
9472 KB |
Output is correct |
16 |
Correct |
67 ms |
10924 KB |
Output is correct |
17 |
Correct |
67 ms |
10992 KB |
Output is correct |
18 |
Correct |
38 ms |
10560 KB |
Output is correct |
19 |
Correct |
38 ms |
10716 KB |
Output is correct |
20 |
Correct |
1 ms |
344 KB |
Output is correct |
21 |
Correct |
133 ms |
11996 KB |
Output is correct |
22 |
Correct |
133 ms |
10644 KB |
Output is correct |
23 |
Correct |
132 ms |
10512 KB |
Output is correct |
24 |
Correct |
143 ms |
10720 KB |
Output is correct |
25 |
Correct |
130 ms |
10688 KB |
Output is correct |
26 |
Correct |
131 ms |
10280 KB |
Output is correct |
27 |
Correct |
140 ms |
10428 KB |
Output is correct |
28 |
Correct |
61 ms |
11352 KB |
Output is correct |
29 |
Correct |
68 ms |
11984 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
86 ms |
15696 KB |
Output is correct |
3 |
Correct |
98 ms |
15076 KB |
Output is correct |
4 |
Correct |
88 ms |
15488 KB |
Output is correct |
5 |
Correct |
89 ms |
15312 KB |
Output is correct |
6 |
Correct |
94 ms |
15784 KB |
Output is correct |
7 |
Correct |
85 ms |
14812 KB |
Output is correct |
8 |
Correct |
94 ms |
15292 KB |
Output is correct |
9 |
Correct |
83 ms |
15720 KB |
Output is correct |
10 |
Correct |
81 ms |
15360 KB |
Output is correct |
11 |
Correct |
42 ms |
9420 KB |
Output is correct |
12 |
Correct |
43 ms |
10176 KB |
Output is correct |
13 |
Correct |
42 ms |
9268 KB |
Output is correct |
14 |
Correct |
43 ms |
10436 KB |
Output is correct |
15 |
Correct |
42 ms |
9516 KB |
Output is correct |
16 |
Correct |
41 ms |
9680 KB |
Output is correct |
17 |
Correct |
44 ms |
10720 KB |
Output is correct |
18 |
Correct |
40 ms |
9156 KB |
Output is correct |
19 |
Correct |
41 ms |
10692 KB |
Output is correct |
20 |
Correct |
0 ms |
344 KB |
Output is correct |
21 |
Correct |
61 ms |
10744 KB |
Output is correct |
22 |
Correct |
60 ms |
9572 KB |
Output is correct |
23 |
Correct |
65 ms |
9564 KB |
Output is correct |
24 |
Correct |
60 ms |
10124 KB |
Output is correct |
25 |
Correct |
70 ms |
9472 KB |
Output is correct |
26 |
Correct |
67 ms |
10924 KB |
Output is correct |
27 |
Correct |
67 ms |
10992 KB |
Output is correct |
28 |
Correct |
38 ms |
10560 KB |
Output is correct |
29 |
Correct |
38 ms |
10716 KB |
Output is correct |
30 |
Correct |
1 ms |
344 KB |
Output is correct |
31 |
Correct |
1 ms |
348 KB |
Output is correct |
32 |
Correct |
1 ms |
344 KB |
Output is correct |
33 |
Correct |
1 ms |
600 KB |
Output is correct |
34 |
Correct |
1 ms |
344 KB |
Output is correct |
35 |
Correct |
1 ms |
344 KB |
Output is correct |
36 |
Correct |
1 ms |
348 KB |
Output is correct |
37 |
Correct |
1 ms |
348 KB |
Output is correct |
38 |
Correct |
1 ms |
348 KB |
Output is correct |
39 |
Correct |
1 ms |
348 KB |
Output is correct |
40 |
Correct |
1 ms |
348 KB |
Output is correct |
41 |
Correct |
5 ms |
860 KB |
Output is correct |
42 |
Correct |
5 ms |
856 KB |
Output is correct |
43 |
Correct |
5 ms |
860 KB |
Output is correct |
44 |
Correct |
4 ms |
988 KB |
Output is correct |
45 |
Correct |
5 ms |
864 KB |
Output is correct |
46 |
Correct |
5 ms |
860 KB |
Output is correct |
47 |
Correct |
5 ms |
856 KB |
Output is correct |
48 |
Correct |
6 ms |
860 KB |
Output is correct |
49 |
Correct |
3 ms |
932 KB |
Output is correct |
50 |
Correct |
0 ms |
348 KB |
Output is correct |
51 |
Correct |
133 ms |
11996 KB |
Output is correct |
52 |
Correct |
133 ms |
10644 KB |
Output is correct |
53 |
Correct |
132 ms |
10512 KB |
Output is correct |
54 |
Correct |
143 ms |
10720 KB |
Output is correct |
55 |
Correct |
130 ms |
10688 KB |
Output is correct |
56 |
Correct |
131 ms |
10280 KB |
Output is correct |
57 |
Correct |
140 ms |
10428 KB |
Output is correct |
58 |
Correct |
61 ms |
11352 KB |
Output is correct |
59 |
Correct |
68 ms |
11984 KB |
Output is correct |
60 |
Correct |
1 ms |
348 KB |
Output is correct |
61 |
Correct |
177 ms |
15148 KB |
Output is correct |
62 |
Correct |
177 ms |
15580 KB |
Output is correct |
63 |
Correct |
189 ms |
14848 KB |
Output is correct |
64 |
Correct |
162 ms |
14784 KB |
Output is correct |
65 |
Correct |
157 ms |
14424 KB |
Output is correct |
66 |
Correct |
167 ms |
14336 KB |
Output is correct |
67 |
Correct |
156 ms |
14336 KB |
Output is correct |
68 |
Correct |
157 ms |
15868 KB |
Output is correct |
69 |
Correct |
135 ms |
10692 KB |
Output is correct |
70 |
Correct |
0 ms |
348 KB |
Output is correct |