// Success consists of going from failure to failure without loss of enthusiasm
#include <bits/stdc++.h>
using namespace std;
#define nl '\n'
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define sz(x) int(x.size())
template<class T> using V = vector<T>;
using vi = V<int>;
using ll = long long;
using pi = pair<int, int>;
using vpi = V<pi>;
using vl = V<ll>;
using db = long double;
const int INF = 1e9 + 10;
struct BIT {
int N; vl A; void init(int n) { N = n; A = vl(N, 0); }
void upd(int p, int x) { for(++p;p<=N;p+=p&-p) A[p-1] += x; }
ll sum(int l, int r) { return sum(r + 1) - sum(l); }
ll sum(int r) { ll s = 0; for(;r;r-=r&-r) s += A[r-1]; return s; }
};
int main() {
cin.tie(0)->sync_with_stdio(0);
int N; cin >> N;
vl A(N); for(auto& x : A) cin >> x;
int M = -1;
{
map<ll, int> C; int cur = 0;
for(auto& x : A) C[x]++;
for(auto& x : C) x.s = cur++;
for(auto& x : A) x = C[x];
M = cur;
}
BIT up, dwn; up.init(M); dwn.init(M);
ll ans = 0;
for(auto& x : A) {
ans += dwn.sum(x + 1, M - 1);
ll DWN = up.sum(0, x - 1);
dwn.upd(x, DWN);
up.upd(x, 1);
}
cout << ans << nl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
312 KB |
Output is correct |
2 |
Correct |
133 ms |
27060 KB |
Output is correct |
3 |
Correct |
134 ms |
26900 KB |
Output is correct |
4 |
Correct |
131 ms |
26980 KB |
Output is correct |
5 |
Correct |
154 ms |
26960 KB |
Output is correct |
6 |
Correct |
130 ms |
26972 KB |
Output is correct |
7 |
Correct |
158 ms |
26900 KB |
Output is correct |
8 |
Correct |
142 ms |
26968 KB |
Output is correct |
9 |
Correct |
112 ms |
17896 KB |
Output is correct |
10 |
Correct |
110 ms |
17864 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
19 ms |
3156 KB |
Output is correct |
2 |
Correct |
21 ms |
3156 KB |
Output is correct |
3 |
Correct |
20 ms |
3156 KB |
Output is correct |
4 |
Correct |
19 ms |
3180 KB |
Output is correct |
5 |
Correct |
19 ms |
3176 KB |
Output is correct |
6 |
Correct |
19 ms |
3156 KB |
Output is correct |
7 |
Correct |
19 ms |
3156 KB |
Output is correct |
8 |
Correct |
14 ms |
3156 KB |
Output is correct |
9 |
Correct |
15 ms |
3152 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
19 ms |
3156 KB |
Output is correct |
2 |
Correct |
21 ms |
3156 KB |
Output is correct |
3 |
Correct |
20 ms |
3156 KB |
Output is correct |
4 |
Correct |
19 ms |
3180 KB |
Output is correct |
5 |
Correct |
19 ms |
3176 KB |
Output is correct |
6 |
Correct |
19 ms |
3156 KB |
Output is correct |
7 |
Correct |
19 ms |
3156 KB |
Output is correct |
8 |
Correct |
14 ms |
3156 KB |
Output is correct |
9 |
Correct |
15 ms |
3152 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
40 ms |
3540 KB |
Output is correct |
12 |
Correct |
46 ms |
3440 KB |
Output is correct |
13 |
Correct |
42 ms |
3464 KB |
Output is correct |
14 |
Correct |
43 ms |
3536 KB |
Output is correct |
15 |
Correct |
41 ms |
3436 KB |
Output is correct |
16 |
Correct |
43 ms |
3440 KB |
Output is correct |
17 |
Correct |
40 ms |
3412 KB |
Output is correct |
18 |
Correct |
22 ms |
3540 KB |
Output is correct |
19 |
Correct |
20 ms |
3412 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
328 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
328 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
5 ms |
1108 KB |
Output is correct |
12 |
Correct |
5 ms |
1104 KB |
Output is correct |
13 |
Correct |
5 ms |
1108 KB |
Output is correct |
14 |
Correct |
5 ms |
1136 KB |
Output is correct |
15 |
Correct |
5 ms |
1108 KB |
Output is correct |
16 |
Correct |
5 ms |
1108 KB |
Output is correct |
17 |
Correct |
5 ms |
1108 KB |
Output is correct |
18 |
Correct |
4 ms |
844 KB |
Output is correct |
19 |
Correct |
2 ms |
468 KB |
Output is correct |
20 |
Correct |
1 ms |
256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
19 ms |
3156 KB |
Output is correct |
2 |
Correct |
21 ms |
3156 KB |
Output is correct |
3 |
Correct |
20 ms |
3156 KB |
Output is correct |
4 |
Correct |
19 ms |
3180 KB |
Output is correct |
5 |
Correct |
19 ms |
3176 KB |
Output is correct |
6 |
Correct |
19 ms |
3156 KB |
Output is correct |
7 |
Correct |
19 ms |
3156 KB |
Output is correct |
8 |
Correct |
14 ms |
3156 KB |
Output is correct |
9 |
Correct |
15 ms |
3152 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
40 ms |
3540 KB |
Output is correct |
12 |
Correct |
46 ms |
3440 KB |
Output is correct |
13 |
Correct |
42 ms |
3464 KB |
Output is correct |
14 |
Correct |
43 ms |
3536 KB |
Output is correct |
15 |
Correct |
41 ms |
3436 KB |
Output is correct |
16 |
Correct |
43 ms |
3440 KB |
Output is correct |
17 |
Correct |
40 ms |
3412 KB |
Output is correct |
18 |
Correct |
22 ms |
3540 KB |
Output is correct |
19 |
Correct |
20 ms |
3412 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
151 ms |
10336 KB |
Output is correct |
22 |
Correct |
148 ms |
10264 KB |
Output is correct |
23 |
Correct |
149 ms |
10344 KB |
Output is correct |
24 |
Correct |
164 ms |
10432 KB |
Output is correct |
25 |
Correct |
150 ms |
10316 KB |
Output is correct |
26 |
Correct |
148 ms |
10344 KB |
Output is correct |
27 |
Correct |
149 ms |
10260 KB |
Output is correct |
28 |
Correct |
88 ms |
10316 KB |
Output is correct |
29 |
Correct |
78 ms |
10316 KB |
Output is correct |
30 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
312 KB |
Output is correct |
2 |
Correct |
133 ms |
27060 KB |
Output is correct |
3 |
Correct |
134 ms |
26900 KB |
Output is correct |
4 |
Correct |
131 ms |
26980 KB |
Output is correct |
5 |
Correct |
154 ms |
26960 KB |
Output is correct |
6 |
Correct |
130 ms |
26972 KB |
Output is correct |
7 |
Correct |
158 ms |
26900 KB |
Output is correct |
8 |
Correct |
142 ms |
26968 KB |
Output is correct |
9 |
Correct |
112 ms |
17896 KB |
Output is correct |
10 |
Correct |
110 ms |
17864 KB |
Output is correct |
11 |
Correct |
19 ms |
3156 KB |
Output is correct |
12 |
Correct |
21 ms |
3156 KB |
Output is correct |
13 |
Correct |
20 ms |
3156 KB |
Output is correct |
14 |
Correct |
19 ms |
3180 KB |
Output is correct |
15 |
Correct |
19 ms |
3176 KB |
Output is correct |
16 |
Correct |
19 ms |
3156 KB |
Output is correct |
17 |
Correct |
19 ms |
3156 KB |
Output is correct |
18 |
Correct |
14 ms |
3156 KB |
Output is correct |
19 |
Correct |
15 ms |
3152 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
40 ms |
3540 KB |
Output is correct |
22 |
Correct |
46 ms |
3440 KB |
Output is correct |
23 |
Correct |
42 ms |
3464 KB |
Output is correct |
24 |
Correct |
43 ms |
3536 KB |
Output is correct |
25 |
Correct |
41 ms |
3436 KB |
Output is correct |
26 |
Correct |
43 ms |
3440 KB |
Output is correct |
27 |
Correct |
40 ms |
3412 KB |
Output is correct |
28 |
Correct |
22 ms |
3540 KB |
Output is correct |
29 |
Correct |
20 ms |
3412 KB |
Output is correct |
30 |
Correct |
1 ms |
212 KB |
Output is correct |
31 |
Correct |
1 ms |
340 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
1 ms |
340 KB |
Output is correct |
34 |
Correct |
1 ms |
332 KB |
Output is correct |
35 |
Correct |
1 ms |
340 KB |
Output is correct |
36 |
Correct |
1 ms |
340 KB |
Output is correct |
37 |
Correct |
1 ms |
340 KB |
Output is correct |
38 |
Correct |
1 ms |
340 KB |
Output is correct |
39 |
Correct |
0 ms |
328 KB |
Output is correct |
40 |
Correct |
0 ms |
212 KB |
Output is correct |
41 |
Correct |
5 ms |
1108 KB |
Output is correct |
42 |
Correct |
5 ms |
1104 KB |
Output is correct |
43 |
Correct |
5 ms |
1108 KB |
Output is correct |
44 |
Correct |
5 ms |
1136 KB |
Output is correct |
45 |
Correct |
5 ms |
1108 KB |
Output is correct |
46 |
Correct |
5 ms |
1108 KB |
Output is correct |
47 |
Correct |
5 ms |
1108 KB |
Output is correct |
48 |
Correct |
4 ms |
844 KB |
Output is correct |
49 |
Correct |
2 ms |
468 KB |
Output is correct |
50 |
Correct |
1 ms |
256 KB |
Output is correct |
51 |
Correct |
151 ms |
10336 KB |
Output is correct |
52 |
Correct |
148 ms |
10264 KB |
Output is correct |
53 |
Correct |
149 ms |
10344 KB |
Output is correct |
54 |
Correct |
164 ms |
10432 KB |
Output is correct |
55 |
Correct |
150 ms |
10316 KB |
Output is correct |
56 |
Correct |
148 ms |
10344 KB |
Output is correct |
57 |
Correct |
149 ms |
10260 KB |
Output is correct |
58 |
Correct |
88 ms |
10316 KB |
Output is correct |
59 |
Correct |
78 ms |
10316 KB |
Output is correct |
60 |
Correct |
0 ms |
212 KB |
Output is correct |
61 |
Correct |
319 ms |
27000 KB |
Output is correct |
62 |
Correct |
358 ms |
26996 KB |
Output is correct |
63 |
Correct |
322 ms |
27000 KB |
Output is correct |
64 |
Correct |
374 ms |
27072 KB |
Output is correct |
65 |
Correct |
305 ms |
27000 KB |
Output is correct |
66 |
Correct |
365 ms |
26996 KB |
Output is correct |
67 |
Correct |
325 ms |
27008 KB |
Output is correct |
68 |
Correct |
200 ms |
17888 KB |
Output is correct |
69 |
Correct |
189 ms |
12524 KB |
Output is correct |
70 |
Correct |
1 ms |
212 KB |
Output is correct |