#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int,int>
#define fi first
#define se second
#define mp make_pair
const int N = 3e5 + 5;
int n,a[N],bit[N],f[N];
void compress() {
vector<pii>vec;
for (int i = 1; i <= n; i++) vec.push_back(mp(a[i],i));
sort(vec.begin(),vec.end());
a[vec[0].se] = 1;
for (int i = 1; i < n; i++)
if (vec[i].fi == vec[i - 1].fi) a[vec[i].se] = a[vec[i - 1].se];
else a[vec[i].se] = i + 1;
}
void update(int i,int x) {
for (; i < N; i += i & (-i)) bit[i] += x;
}
int get(int i) {
int ans = 0;
for (; i > 0; i -= i & (-i)) ans += bit[i];
return ans;
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i];
compress();
for (int i = 1; i <= n; i++) {
f[i] = get(a[i] - 1);
update(a[i],1);
}
memset(bit,0,sizeof(bit));
int ans = 0;
for (int i = n; i > 0; i--) {
ans += get(a[i] - 1) * f[i];
update(a[i],1);
}
cout << ans << "\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4440 KB |
Output is correct |
2 |
Correct |
64 ms |
18552 KB |
Output is correct |
3 |
Correct |
60 ms |
18740 KB |
Output is correct |
4 |
Correct |
60 ms |
17328 KB |
Output is correct |
5 |
Correct |
63 ms |
17736 KB |
Output is correct |
6 |
Correct |
58 ms |
18376 KB |
Output is correct |
7 |
Correct |
58 ms |
18736 KB |
Output is correct |
8 |
Correct |
59 ms |
17512 KB |
Output is correct |
9 |
Correct |
64 ms |
17872 KB |
Output is correct |
10 |
Correct |
67 ms |
17460 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
77 ms |
13000 KB |
Output is correct |
2 |
Correct |
85 ms |
13008 KB |
Output is correct |
3 |
Correct |
81 ms |
11972 KB |
Output is correct |
4 |
Correct |
79 ms |
12744 KB |
Output is correct |
5 |
Correct |
76 ms |
12332 KB |
Output is correct |
6 |
Correct |
81 ms |
13772 KB |
Output is correct |
7 |
Correct |
81 ms |
12228 KB |
Output is correct |
8 |
Correct |
49 ms |
14224 KB |
Output is correct |
9 |
Correct |
48 ms |
13004 KB |
Output is correct |
10 |
Correct |
1 ms |
4856 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
77 ms |
13000 KB |
Output is correct |
2 |
Correct |
85 ms |
13008 KB |
Output is correct |
3 |
Correct |
81 ms |
11972 KB |
Output is correct |
4 |
Correct |
79 ms |
12744 KB |
Output is correct |
5 |
Correct |
76 ms |
12332 KB |
Output is correct |
6 |
Correct |
81 ms |
13772 KB |
Output is correct |
7 |
Correct |
81 ms |
12228 KB |
Output is correct |
8 |
Correct |
49 ms |
14224 KB |
Output is correct |
9 |
Correct |
48 ms |
13004 KB |
Output is correct |
10 |
Correct |
1 ms |
4856 KB |
Output is correct |
11 |
Correct |
89 ms |
12884 KB |
Output is correct |
12 |
Correct |
93 ms |
12488 KB |
Output is correct |
13 |
Correct |
92 ms |
13260 KB |
Output is correct |
14 |
Correct |
90 ms |
12732 KB |
Output is correct |
15 |
Correct |
77 ms |
13008 KB |
Output is correct |
16 |
Correct |
111 ms |
13520 KB |
Output is correct |
17 |
Correct |
93 ms |
13256 KB |
Output is correct |
18 |
Correct |
38 ms |
13264 KB |
Output is correct |
19 |
Correct |
38 ms |
13508 KB |
Output is correct |
20 |
Correct |
1 ms |
4440 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
2 ms |
4444 KB |
Output is correct |
3 |
Correct |
2 ms |
4444 KB |
Output is correct |
4 |
Correct |
2 ms |
4444 KB |
Output is correct |
5 |
Correct |
2 ms |
4444 KB |
Output is correct |
6 |
Correct |
2 ms |
4312 KB |
Output is correct |
7 |
Correct |
1 ms |
4316 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
2 ms |
4444 KB |
Output is correct |
3 |
Correct |
2 ms |
4444 KB |
Output is correct |
4 |
Correct |
2 ms |
4444 KB |
Output is correct |
5 |
Correct |
2 ms |
4444 KB |
Output is correct |
6 |
Correct |
2 ms |
4312 KB |
Output is correct |
7 |
Correct |
1 ms |
4316 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
4 ms |
4672 KB |
Output is correct |
12 |
Correct |
5 ms |
4616 KB |
Output is correct |
13 |
Correct |
4 ms |
4672 KB |
Output is correct |
14 |
Correct |
4 ms |
4672 KB |
Output is correct |
15 |
Correct |
5 ms |
4732 KB |
Output is correct |
16 |
Correct |
5 ms |
4672 KB |
Output is correct |
17 |
Correct |
4 ms |
4672 KB |
Output is correct |
18 |
Correct |
4 ms |
4672 KB |
Output is correct |
19 |
Correct |
4 ms |
4672 KB |
Output is correct |
20 |
Correct |
1 ms |
4444 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
77 ms |
13000 KB |
Output is correct |
2 |
Correct |
85 ms |
13008 KB |
Output is correct |
3 |
Correct |
81 ms |
11972 KB |
Output is correct |
4 |
Correct |
79 ms |
12744 KB |
Output is correct |
5 |
Correct |
76 ms |
12332 KB |
Output is correct |
6 |
Correct |
81 ms |
13772 KB |
Output is correct |
7 |
Correct |
81 ms |
12228 KB |
Output is correct |
8 |
Correct |
49 ms |
14224 KB |
Output is correct |
9 |
Correct |
48 ms |
13004 KB |
Output is correct |
10 |
Correct |
1 ms |
4856 KB |
Output is correct |
11 |
Correct |
89 ms |
12884 KB |
Output is correct |
12 |
Correct |
93 ms |
12488 KB |
Output is correct |
13 |
Correct |
92 ms |
13260 KB |
Output is correct |
14 |
Correct |
90 ms |
12732 KB |
Output is correct |
15 |
Correct |
77 ms |
13008 KB |
Output is correct |
16 |
Correct |
111 ms |
13520 KB |
Output is correct |
17 |
Correct |
93 ms |
13256 KB |
Output is correct |
18 |
Correct |
38 ms |
13264 KB |
Output is correct |
19 |
Correct |
38 ms |
13508 KB |
Output is correct |
20 |
Correct |
1 ms |
4440 KB |
Output is correct |
21 |
Correct |
93 ms |
14284 KB |
Output is correct |
22 |
Correct |
85 ms |
14000 KB |
Output is correct |
23 |
Correct |
95 ms |
15056 KB |
Output is correct |
24 |
Correct |
98 ms |
13500 KB |
Output is correct |
25 |
Correct |
96 ms |
14788 KB |
Output is correct |
26 |
Correct |
95 ms |
14792 KB |
Output is correct |
27 |
Correct |
90 ms |
14516 KB |
Output is correct |
28 |
Correct |
49 ms |
13296 KB |
Output is correct |
29 |
Correct |
46 ms |
14532 KB |
Output is correct |
30 |
Correct |
1 ms |
4444 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4440 KB |
Output is correct |
2 |
Correct |
64 ms |
18552 KB |
Output is correct |
3 |
Correct |
60 ms |
18740 KB |
Output is correct |
4 |
Correct |
60 ms |
17328 KB |
Output is correct |
5 |
Correct |
63 ms |
17736 KB |
Output is correct |
6 |
Correct |
58 ms |
18376 KB |
Output is correct |
7 |
Correct |
58 ms |
18736 KB |
Output is correct |
8 |
Correct |
59 ms |
17512 KB |
Output is correct |
9 |
Correct |
64 ms |
17872 KB |
Output is correct |
10 |
Correct |
67 ms |
17460 KB |
Output is correct |
11 |
Correct |
77 ms |
13000 KB |
Output is correct |
12 |
Correct |
85 ms |
13008 KB |
Output is correct |
13 |
Correct |
81 ms |
11972 KB |
Output is correct |
14 |
Correct |
79 ms |
12744 KB |
Output is correct |
15 |
Correct |
76 ms |
12332 KB |
Output is correct |
16 |
Correct |
81 ms |
13772 KB |
Output is correct |
17 |
Correct |
81 ms |
12228 KB |
Output is correct |
18 |
Correct |
49 ms |
14224 KB |
Output is correct |
19 |
Correct |
48 ms |
13004 KB |
Output is correct |
20 |
Correct |
1 ms |
4856 KB |
Output is correct |
21 |
Correct |
89 ms |
12884 KB |
Output is correct |
22 |
Correct |
93 ms |
12488 KB |
Output is correct |
23 |
Correct |
92 ms |
13260 KB |
Output is correct |
24 |
Correct |
90 ms |
12732 KB |
Output is correct |
25 |
Correct |
77 ms |
13008 KB |
Output is correct |
26 |
Correct |
111 ms |
13520 KB |
Output is correct |
27 |
Correct |
93 ms |
13256 KB |
Output is correct |
28 |
Correct |
38 ms |
13264 KB |
Output is correct |
29 |
Correct |
38 ms |
13508 KB |
Output is correct |
30 |
Correct |
1 ms |
4440 KB |
Output is correct |
31 |
Correct |
1 ms |
4444 KB |
Output is correct |
32 |
Correct |
2 ms |
4444 KB |
Output is correct |
33 |
Correct |
2 ms |
4444 KB |
Output is correct |
34 |
Correct |
2 ms |
4444 KB |
Output is correct |
35 |
Correct |
2 ms |
4444 KB |
Output is correct |
36 |
Correct |
2 ms |
4312 KB |
Output is correct |
37 |
Correct |
1 ms |
4316 KB |
Output is correct |
38 |
Correct |
1 ms |
4444 KB |
Output is correct |
39 |
Correct |
1 ms |
4444 KB |
Output is correct |
40 |
Correct |
1 ms |
4444 KB |
Output is correct |
41 |
Correct |
4 ms |
4672 KB |
Output is correct |
42 |
Correct |
5 ms |
4616 KB |
Output is correct |
43 |
Correct |
4 ms |
4672 KB |
Output is correct |
44 |
Correct |
4 ms |
4672 KB |
Output is correct |
45 |
Correct |
5 ms |
4732 KB |
Output is correct |
46 |
Correct |
5 ms |
4672 KB |
Output is correct |
47 |
Correct |
4 ms |
4672 KB |
Output is correct |
48 |
Correct |
4 ms |
4672 KB |
Output is correct |
49 |
Correct |
4 ms |
4672 KB |
Output is correct |
50 |
Correct |
1 ms |
4444 KB |
Output is correct |
51 |
Correct |
93 ms |
14284 KB |
Output is correct |
52 |
Correct |
85 ms |
14000 KB |
Output is correct |
53 |
Correct |
95 ms |
15056 KB |
Output is correct |
54 |
Correct |
98 ms |
13500 KB |
Output is correct |
55 |
Correct |
96 ms |
14788 KB |
Output is correct |
56 |
Correct |
95 ms |
14792 KB |
Output is correct |
57 |
Correct |
90 ms |
14516 KB |
Output is correct |
58 |
Correct |
49 ms |
13296 KB |
Output is correct |
59 |
Correct |
46 ms |
14532 KB |
Output is correct |
60 |
Correct |
1 ms |
4444 KB |
Output is correct |
61 |
Correct |
105 ms |
17136 KB |
Output is correct |
62 |
Correct |
106 ms |
18676 KB |
Output is correct |
63 |
Correct |
114 ms |
18732 KB |
Output is correct |
64 |
Correct |
107 ms |
18628 KB |
Output is correct |
65 |
Correct |
96 ms |
18120 KB |
Output is correct |
66 |
Correct |
111 ms |
18376 KB |
Output is correct |
67 |
Correct |
115 ms |
17616 KB |
Output is correct |
68 |
Correct |
101 ms |
17092 KB |
Output is correct |
69 |
Correct |
92 ms |
13240 KB |
Output is correct |
70 |
Correct |
1 ms |
4444 KB |
Output is correct |