#include<bits/stdc++.h>
using namespace std;
#define int long long
struct FenwickTree{
int n;
vector<int> t;
void init(int _n){
n=_n;
t.assign(n+1, 0);
}
void update(int pos, int val){
for (int i=pos; i<=n; i+=i&(-i)) t[i]+=val;
}
int get(int pos){
int ans=0;
for (int i=pos; i; i-=i&(-i)) ans+=t[i];
return ans;
}
int get(int l, int r){
return get(r)-get(l-1);
}
} bit;
const int N=3e5+1;
int n, a[N];
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n;
map<int, vector<int>> mp;
for (int i=1; i<=n; ++i) cin >> a[i], mp[a[i]].push_back(i);
bit.init(n);
int ans=0;
for (auto &i:mp){
for (int j:i.second){
ans+=bit.get(j-1)*bit.get(j+1, n);
}
for (int j:i.second) bit.update(j, 1);
}
cout << ans;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
118 ms |
43504 KB |
Output is correct |
3 |
Correct |
123 ms |
43428 KB |
Output is correct |
4 |
Correct |
119 ms |
43344 KB |
Output is correct |
5 |
Correct |
120 ms |
43516 KB |
Output is correct |
6 |
Correct |
120 ms |
43340 KB |
Output is correct |
7 |
Correct |
120 ms |
43348 KB |
Output is correct |
8 |
Correct |
120 ms |
43348 KB |
Output is correct |
9 |
Correct |
93 ms |
28236 KB |
Output is correct |
10 |
Correct |
90 ms |
28288 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
27 ms |
8064 KB |
Output is correct |
2 |
Correct |
27 ms |
8296 KB |
Output is correct |
3 |
Correct |
27 ms |
8124 KB |
Output is correct |
4 |
Correct |
26 ms |
8224 KB |
Output is correct |
5 |
Correct |
30 ms |
8060 KB |
Output is correct |
6 |
Correct |
27 ms |
8128 KB |
Output is correct |
7 |
Correct |
27 ms |
8172 KB |
Output is correct |
8 |
Correct |
27 ms |
8332 KB |
Output is correct |
9 |
Correct |
21 ms |
8024 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
27 ms |
8064 KB |
Output is correct |
2 |
Correct |
27 ms |
8296 KB |
Output is correct |
3 |
Correct |
27 ms |
8124 KB |
Output is correct |
4 |
Correct |
26 ms |
8224 KB |
Output is correct |
5 |
Correct |
30 ms |
8060 KB |
Output is correct |
6 |
Correct |
27 ms |
8128 KB |
Output is correct |
7 |
Correct |
27 ms |
8172 KB |
Output is correct |
8 |
Correct |
27 ms |
8332 KB |
Output is correct |
9 |
Correct |
21 ms |
8024 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
37 ms |
9424 KB |
Output is correct |
12 |
Correct |
37 ms |
9164 KB |
Output is correct |
13 |
Correct |
37 ms |
9304 KB |
Output is correct |
14 |
Correct |
37 ms |
9552 KB |
Output is correct |
15 |
Correct |
38 ms |
9344 KB |
Output is correct |
16 |
Correct |
37 ms |
9308 KB |
Output is correct |
17 |
Correct |
40 ms |
9560 KB |
Output is correct |
18 |
Correct |
24 ms |
8692 KB |
Output is correct |
19 |
Correct |
25 ms |
8796 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 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 |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 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 |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
5 ms |
1880 KB |
Output is correct |
12 |
Correct |
5 ms |
1884 KB |
Output is correct |
13 |
Correct |
5 ms |
1884 KB |
Output is correct |
14 |
Correct |
5 ms |
1884 KB |
Output is correct |
15 |
Correct |
5 ms |
1812 KB |
Output is correct |
16 |
Correct |
5 ms |
1880 KB |
Output is correct |
17 |
Correct |
5 ms |
1880 KB |
Output is correct |
18 |
Correct |
5 ms |
1184 KB |
Output is correct |
19 |
Correct |
2 ms |
860 KB |
Output is correct |
20 |
Correct |
0 ms |
408 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
27 ms |
8064 KB |
Output is correct |
2 |
Correct |
27 ms |
8296 KB |
Output is correct |
3 |
Correct |
27 ms |
8124 KB |
Output is correct |
4 |
Correct |
26 ms |
8224 KB |
Output is correct |
5 |
Correct |
30 ms |
8060 KB |
Output is correct |
6 |
Correct |
27 ms |
8128 KB |
Output is correct |
7 |
Correct |
27 ms |
8172 KB |
Output is correct |
8 |
Correct |
27 ms |
8332 KB |
Output is correct |
9 |
Correct |
21 ms |
8024 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
37 ms |
9424 KB |
Output is correct |
12 |
Correct |
37 ms |
9164 KB |
Output is correct |
13 |
Correct |
37 ms |
9304 KB |
Output is correct |
14 |
Correct |
37 ms |
9552 KB |
Output is correct |
15 |
Correct |
38 ms |
9344 KB |
Output is correct |
16 |
Correct |
37 ms |
9308 KB |
Output is correct |
17 |
Correct |
40 ms |
9560 KB |
Output is correct |
18 |
Correct |
24 ms |
8692 KB |
Output is correct |
19 |
Correct |
25 ms |
8796 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
152 ms |
19204 KB |
Output is correct |
22 |
Correct |
163 ms |
19352 KB |
Output is correct |
23 |
Correct |
220 ms |
19392 KB |
Output is correct |
24 |
Correct |
166 ms |
19164 KB |
Output is correct |
25 |
Correct |
173 ms |
19256 KB |
Output is correct |
26 |
Correct |
139 ms |
19364 KB |
Output is correct |
27 |
Correct |
197 ms |
19312 KB |
Output is correct |
28 |
Correct |
66 ms |
18720 KB |
Output is correct |
29 |
Correct |
65 ms |
18772 KB |
Output is correct |
30 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
118 ms |
43504 KB |
Output is correct |
3 |
Correct |
123 ms |
43428 KB |
Output is correct |
4 |
Correct |
119 ms |
43344 KB |
Output is correct |
5 |
Correct |
120 ms |
43516 KB |
Output is correct |
6 |
Correct |
120 ms |
43340 KB |
Output is correct |
7 |
Correct |
120 ms |
43348 KB |
Output is correct |
8 |
Correct |
120 ms |
43348 KB |
Output is correct |
9 |
Correct |
93 ms |
28236 KB |
Output is correct |
10 |
Correct |
90 ms |
28288 KB |
Output is correct |
11 |
Correct |
27 ms |
8064 KB |
Output is correct |
12 |
Correct |
27 ms |
8296 KB |
Output is correct |
13 |
Correct |
27 ms |
8124 KB |
Output is correct |
14 |
Correct |
26 ms |
8224 KB |
Output is correct |
15 |
Correct |
30 ms |
8060 KB |
Output is correct |
16 |
Correct |
27 ms |
8128 KB |
Output is correct |
17 |
Correct |
27 ms |
8172 KB |
Output is correct |
18 |
Correct |
27 ms |
8332 KB |
Output is correct |
19 |
Correct |
21 ms |
8024 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
37 ms |
9424 KB |
Output is correct |
22 |
Correct |
37 ms |
9164 KB |
Output is correct |
23 |
Correct |
37 ms |
9304 KB |
Output is correct |
24 |
Correct |
37 ms |
9552 KB |
Output is correct |
25 |
Correct |
38 ms |
9344 KB |
Output is correct |
26 |
Correct |
37 ms |
9308 KB |
Output is correct |
27 |
Correct |
40 ms |
9560 KB |
Output is correct |
28 |
Correct |
24 ms |
8692 KB |
Output is correct |
29 |
Correct |
25 ms |
8796 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
1 ms |
348 KB |
Output is correct |
32 |
Correct |
1 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
1 ms |
348 KB |
Output is correct |
35 |
Correct |
1 ms |
348 KB |
Output is correct |
36 |
Correct |
0 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 |
0 ms |
348 KB |
Output is correct |
40 |
Correct |
0 ms |
348 KB |
Output is correct |
41 |
Correct |
5 ms |
1880 KB |
Output is correct |
42 |
Correct |
5 ms |
1884 KB |
Output is correct |
43 |
Correct |
5 ms |
1884 KB |
Output is correct |
44 |
Correct |
5 ms |
1884 KB |
Output is correct |
45 |
Correct |
5 ms |
1812 KB |
Output is correct |
46 |
Correct |
5 ms |
1880 KB |
Output is correct |
47 |
Correct |
5 ms |
1880 KB |
Output is correct |
48 |
Correct |
5 ms |
1184 KB |
Output is correct |
49 |
Correct |
2 ms |
860 KB |
Output is correct |
50 |
Correct |
0 ms |
408 KB |
Output is correct |
51 |
Correct |
152 ms |
19204 KB |
Output is correct |
52 |
Correct |
163 ms |
19352 KB |
Output is correct |
53 |
Correct |
220 ms |
19392 KB |
Output is correct |
54 |
Correct |
166 ms |
19164 KB |
Output is correct |
55 |
Correct |
173 ms |
19256 KB |
Output is correct |
56 |
Correct |
139 ms |
19364 KB |
Output is correct |
57 |
Correct |
197 ms |
19312 KB |
Output is correct |
58 |
Correct |
66 ms |
18720 KB |
Output is correct |
59 |
Correct |
65 ms |
18772 KB |
Output is correct |
60 |
Correct |
0 ms |
344 KB |
Output is correct |
61 |
Correct |
290 ms |
43324 KB |
Output is correct |
62 |
Correct |
321 ms |
43380 KB |
Output is correct |
63 |
Correct |
337 ms |
43448 KB |
Output is correct |
64 |
Correct |
350 ms |
43600 KB |
Output is correct |
65 |
Correct |
347 ms |
43504 KB |
Output is correct |
66 |
Correct |
352 ms |
43324 KB |
Output is correct |
67 |
Correct |
313 ms |
43544 KB |
Output is correct |
68 |
Correct |
300 ms |
28240 KB |
Output is correct |
69 |
Correct |
246 ms |
22376 KB |
Output is correct |
70 |
Correct |
1 ms |
348 KB |
Output is correct |