#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define MAXN (300005)
struct plot {
ll fw[MAXN];
plot() {
memset(fw,0,sizeof fw);
}
void update(int x,ll nval) {
for(;x<MAXN;x+=x&(-x)) fw[x]+=nval;
}
ll aaa(int x) {
ll res = 0;
for(;x;x-=x&(-x)) res += fw[x];
return res;
}
ll sum(int a,int b) {
return aaa(b) - aaa(a-1);
}
} before, after;
ll N;
int main(){
ios_base::sync_with_stdio(false);cin.tie(0);
cin>>N;
ll arr[N];
ll ans = 0;
vector<ll> d;
for(ll i = 0;i < N;i++){
cin>>arr[i];
d.push_back(arr[i]);
}
sort(d.begin(),d.end());
d.resize(unique(d.begin(),d.end()) - d.begin());
for(ll i = 0;i < N;i++) arr[i] = (lower_bound(d.begin(), d.end(), arr[i]) - d.begin() + 1);
for(ll i = 0;i < N;i++){
before.update(arr[i],1);
}
for(ll i = N - 1;i >= 0;i--){
ans += (before.sum(1,arr[i] - 1) * after.sum(1,arr[i] - 1));
before.update(arr[i],-1);
after.update(arr[i],1);
}
cout<<ans<<'\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
93 ms |
16460 KB |
Output is correct |
3 |
Correct |
94 ms |
16488 KB |
Output is correct |
4 |
Correct |
92 ms |
16472 KB |
Output is correct |
5 |
Correct |
90 ms |
16496 KB |
Output is correct |
6 |
Correct |
91 ms |
16544 KB |
Output is correct |
7 |
Correct |
90 ms |
16508 KB |
Output is correct |
8 |
Correct |
99 ms |
16544 KB |
Output is correct |
9 |
Correct |
91 ms |
16580 KB |
Output is correct |
10 |
Correct |
89 ms |
16604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
62 ms |
12132 KB |
Output is correct |
2 |
Correct |
62 ms |
12168 KB |
Output is correct |
3 |
Correct |
63 ms |
12096 KB |
Output is correct |
4 |
Correct |
62 ms |
12108 KB |
Output is correct |
5 |
Correct |
62 ms |
12068 KB |
Output is correct |
6 |
Correct |
62 ms |
12108 KB |
Output is correct |
7 |
Correct |
63 ms |
12172 KB |
Output is correct |
8 |
Correct |
59 ms |
12120 KB |
Output is correct |
9 |
Correct |
62 ms |
12180 KB |
Output is correct |
10 |
Correct |
2 ms |
4948 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
62 ms |
12132 KB |
Output is correct |
2 |
Correct |
62 ms |
12168 KB |
Output is correct |
3 |
Correct |
63 ms |
12096 KB |
Output is correct |
4 |
Correct |
62 ms |
12108 KB |
Output is correct |
5 |
Correct |
62 ms |
12068 KB |
Output is correct |
6 |
Correct |
62 ms |
12108 KB |
Output is correct |
7 |
Correct |
63 ms |
12172 KB |
Output is correct |
8 |
Correct |
59 ms |
12120 KB |
Output is correct |
9 |
Correct |
62 ms |
12180 KB |
Output is correct |
10 |
Correct |
2 ms |
4948 KB |
Output is correct |
11 |
Correct |
71 ms |
12436 KB |
Output is correct |
12 |
Correct |
70 ms |
12440 KB |
Output is correct |
13 |
Correct |
72 ms |
12404 KB |
Output is correct |
14 |
Correct |
71 ms |
12364 KB |
Output is correct |
15 |
Correct |
78 ms |
12356 KB |
Output is correct |
16 |
Correct |
73 ms |
12356 KB |
Output is correct |
17 |
Correct |
76 ms |
12448 KB |
Output is correct |
18 |
Correct |
54 ms |
12476 KB |
Output is correct |
19 |
Correct |
59 ms |
12356 KB |
Output is correct |
20 |
Correct |
3 ms |
4948 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4992 KB |
Output is correct |
3 |
Correct |
3 ms |
4948 KB |
Output is correct |
4 |
Correct |
2 ms |
4948 KB |
Output is correct |
5 |
Correct |
2 ms |
4948 KB |
Output is correct |
6 |
Correct |
3 ms |
4948 KB |
Output is correct |
7 |
Correct |
2 ms |
5028 KB |
Output is correct |
8 |
Correct |
2 ms |
4948 KB |
Output is correct |
9 |
Correct |
2 ms |
4948 KB |
Output is correct |
10 |
Correct |
2 ms |
4948 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4992 KB |
Output is correct |
3 |
Correct |
3 ms |
4948 KB |
Output is correct |
4 |
Correct |
2 ms |
4948 KB |
Output is correct |
5 |
Correct |
2 ms |
4948 KB |
Output is correct |
6 |
Correct |
3 ms |
4948 KB |
Output is correct |
7 |
Correct |
2 ms |
5028 KB |
Output is correct |
8 |
Correct |
2 ms |
4948 KB |
Output is correct |
9 |
Correct |
2 ms |
4948 KB |
Output is correct |
10 |
Correct |
2 ms |
4948 KB |
Output is correct |
11 |
Correct |
6 ms |
5460 KB |
Output is correct |
12 |
Correct |
7 ms |
5412 KB |
Output is correct |
13 |
Correct |
8 ms |
5388 KB |
Output is correct |
14 |
Correct |
8 ms |
5384 KB |
Output is correct |
15 |
Correct |
6 ms |
5400 KB |
Output is correct |
16 |
Correct |
7 ms |
5412 KB |
Output is correct |
17 |
Correct |
7 ms |
5416 KB |
Output is correct |
18 |
Correct |
8 ms |
5452 KB |
Output is correct |
19 |
Correct |
6 ms |
5320 KB |
Output is correct |
20 |
Correct |
3 ms |
4948 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
62 ms |
12132 KB |
Output is correct |
2 |
Correct |
62 ms |
12168 KB |
Output is correct |
3 |
Correct |
63 ms |
12096 KB |
Output is correct |
4 |
Correct |
62 ms |
12108 KB |
Output is correct |
5 |
Correct |
62 ms |
12068 KB |
Output is correct |
6 |
Correct |
62 ms |
12108 KB |
Output is correct |
7 |
Correct |
63 ms |
12172 KB |
Output is correct |
8 |
Correct |
59 ms |
12120 KB |
Output is correct |
9 |
Correct |
62 ms |
12180 KB |
Output is correct |
10 |
Correct |
2 ms |
4948 KB |
Output is correct |
11 |
Correct |
71 ms |
12436 KB |
Output is correct |
12 |
Correct |
70 ms |
12440 KB |
Output is correct |
13 |
Correct |
72 ms |
12404 KB |
Output is correct |
14 |
Correct |
71 ms |
12364 KB |
Output is correct |
15 |
Correct |
78 ms |
12356 KB |
Output is correct |
16 |
Correct |
73 ms |
12356 KB |
Output is correct |
17 |
Correct |
76 ms |
12448 KB |
Output is correct |
18 |
Correct |
54 ms |
12476 KB |
Output is correct |
19 |
Correct |
59 ms |
12356 KB |
Output is correct |
20 |
Correct |
3 ms |
4948 KB |
Output is correct |
21 |
Correct |
110 ms |
13204 KB |
Output is correct |
22 |
Correct |
113 ms |
13256 KB |
Output is correct |
23 |
Correct |
115 ms |
13236 KB |
Output is correct |
24 |
Correct |
111 ms |
13124 KB |
Output is correct |
25 |
Correct |
111 ms |
13152 KB |
Output is correct |
26 |
Correct |
111 ms |
13200 KB |
Output is correct |
27 |
Correct |
109 ms |
13252 KB |
Output is correct |
28 |
Correct |
60 ms |
13156 KB |
Output is correct |
29 |
Correct |
63 ms |
13260 KB |
Output is correct |
30 |
Correct |
2 ms |
4948 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
93 ms |
16460 KB |
Output is correct |
3 |
Correct |
94 ms |
16488 KB |
Output is correct |
4 |
Correct |
92 ms |
16472 KB |
Output is correct |
5 |
Correct |
90 ms |
16496 KB |
Output is correct |
6 |
Correct |
91 ms |
16544 KB |
Output is correct |
7 |
Correct |
90 ms |
16508 KB |
Output is correct |
8 |
Correct |
99 ms |
16544 KB |
Output is correct |
9 |
Correct |
91 ms |
16580 KB |
Output is correct |
10 |
Correct |
89 ms |
16604 KB |
Output is correct |
11 |
Correct |
62 ms |
12132 KB |
Output is correct |
12 |
Correct |
62 ms |
12168 KB |
Output is correct |
13 |
Correct |
63 ms |
12096 KB |
Output is correct |
14 |
Correct |
62 ms |
12108 KB |
Output is correct |
15 |
Correct |
62 ms |
12068 KB |
Output is correct |
16 |
Correct |
62 ms |
12108 KB |
Output is correct |
17 |
Correct |
63 ms |
12172 KB |
Output is correct |
18 |
Correct |
59 ms |
12120 KB |
Output is correct |
19 |
Correct |
62 ms |
12180 KB |
Output is correct |
20 |
Correct |
2 ms |
4948 KB |
Output is correct |
21 |
Correct |
71 ms |
12436 KB |
Output is correct |
22 |
Correct |
70 ms |
12440 KB |
Output is correct |
23 |
Correct |
72 ms |
12404 KB |
Output is correct |
24 |
Correct |
71 ms |
12364 KB |
Output is correct |
25 |
Correct |
78 ms |
12356 KB |
Output is correct |
26 |
Correct |
73 ms |
12356 KB |
Output is correct |
27 |
Correct |
76 ms |
12448 KB |
Output is correct |
28 |
Correct |
54 ms |
12476 KB |
Output is correct |
29 |
Correct |
59 ms |
12356 KB |
Output is correct |
30 |
Correct |
3 ms |
4948 KB |
Output is correct |
31 |
Correct |
2 ms |
4948 KB |
Output is correct |
32 |
Correct |
3 ms |
4992 KB |
Output is correct |
33 |
Correct |
3 ms |
4948 KB |
Output is correct |
34 |
Correct |
2 ms |
4948 KB |
Output is correct |
35 |
Correct |
2 ms |
4948 KB |
Output is correct |
36 |
Correct |
3 ms |
4948 KB |
Output is correct |
37 |
Correct |
2 ms |
5028 KB |
Output is correct |
38 |
Correct |
2 ms |
4948 KB |
Output is correct |
39 |
Correct |
2 ms |
4948 KB |
Output is correct |
40 |
Correct |
2 ms |
4948 KB |
Output is correct |
41 |
Correct |
6 ms |
5460 KB |
Output is correct |
42 |
Correct |
7 ms |
5412 KB |
Output is correct |
43 |
Correct |
8 ms |
5388 KB |
Output is correct |
44 |
Correct |
8 ms |
5384 KB |
Output is correct |
45 |
Correct |
6 ms |
5400 KB |
Output is correct |
46 |
Correct |
7 ms |
5412 KB |
Output is correct |
47 |
Correct |
7 ms |
5416 KB |
Output is correct |
48 |
Correct |
8 ms |
5452 KB |
Output is correct |
49 |
Correct |
6 ms |
5320 KB |
Output is correct |
50 |
Correct |
3 ms |
4948 KB |
Output is correct |
51 |
Correct |
110 ms |
13204 KB |
Output is correct |
52 |
Correct |
113 ms |
13256 KB |
Output is correct |
53 |
Correct |
115 ms |
13236 KB |
Output is correct |
54 |
Correct |
111 ms |
13124 KB |
Output is correct |
55 |
Correct |
111 ms |
13152 KB |
Output is correct |
56 |
Correct |
111 ms |
13200 KB |
Output is correct |
57 |
Correct |
109 ms |
13252 KB |
Output is correct |
58 |
Correct |
60 ms |
13156 KB |
Output is correct |
59 |
Correct |
63 ms |
13260 KB |
Output is correct |
60 |
Correct |
2 ms |
4948 KB |
Output is correct |
61 |
Correct |
142 ms |
16532 KB |
Output is correct |
62 |
Correct |
145 ms |
16504 KB |
Output is correct |
63 |
Correct |
143 ms |
16584 KB |
Output is correct |
64 |
Correct |
141 ms |
16560 KB |
Output is correct |
65 |
Correct |
138 ms |
16516 KB |
Output is correct |
66 |
Correct |
143 ms |
16580 KB |
Output is correct |
67 |
Correct |
139 ms |
16552 KB |
Output is correct |
68 |
Correct |
136 ms |
16704 KB |
Output is correct |
69 |
Correct |
110 ms |
13344 KB |
Output is correct |
70 |
Correct |
2 ms |
4948 KB |
Output is correct |