#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
const int maxn = 3e5 + 5;
int BIT[maxn];
void upd(int i, int v)
{
for(; i < maxn; i += i & -i)
BIT[i] += v;
}
int sum(int i)
{
int res = 0;
for(; i; i -= i & -i)
res += BIT[i];
return res;
}
signed main(void)
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifdef LOCAL
freopen("A.INP", "r", stdin);
freopen("A.OUT", "w", stdout);
#endif // LOCAL
int n; cin >> n;
vector<ll> a(n); vector<int> l(n), r(n);
vector<ll> val;
for(auto & x : a) cin >> x;
val = a;
sort(val.begin(), val.end()); val.erase(unique(val.begin(), val.end()), val.end());
for(auto & x: a){
x = lower_bound(val.begin(), val.end(), x) - val.begin() + 1;
}
for(int i = 0; i < n; ++i){
l[i] = sum(a[i] - 1);
upd(a[i], 1);
}
for(auto & x : a) upd(x, -1);
ll res = 0;
for(int i = n - 1; i >= 0; --i){
res += 1ll * sum(a[i] - 1) * l[i];
upd(a[i], 1);
}
cout << res;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
117 ms |
14072 KB |
Output is correct |
3 |
Correct |
118 ms |
14204 KB |
Output is correct |
4 |
Correct |
114 ms |
14076 KB |
Output is correct |
5 |
Correct |
115 ms |
14200 KB |
Output is correct |
6 |
Correct |
120 ms |
14196 KB |
Output is correct |
7 |
Correct |
133 ms |
14088 KB |
Output is correct |
8 |
Correct |
116 ms |
14072 KB |
Output is correct |
9 |
Correct |
115 ms |
13432 KB |
Output is correct |
10 |
Correct |
116 ms |
13560 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
79 ms |
8184 KB |
Output is correct |
2 |
Correct |
72 ms |
8060 KB |
Output is correct |
3 |
Correct |
72 ms |
8056 KB |
Output is correct |
4 |
Correct |
71 ms |
8064 KB |
Output is correct |
5 |
Correct |
70 ms |
8056 KB |
Output is correct |
6 |
Correct |
77 ms |
8056 KB |
Output is correct |
7 |
Correct |
74 ms |
8064 KB |
Output is correct |
8 |
Correct |
69 ms |
8064 KB |
Output is correct |
9 |
Correct |
69 ms |
8064 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
79 ms |
8184 KB |
Output is correct |
2 |
Correct |
72 ms |
8060 KB |
Output is correct |
3 |
Correct |
72 ms |
8056 KB |
Output is correct |
4 |
Correct |
71 ms |
8064 KB |
Output is correct |
5 |
Correct |
70 ms |
8056 KB |
Output is correct |
6 |
Correct |
77 ms |
8056 KB |
Output is correct |
7 |
Correct |
74 ms |
8064 KB |
Output is correct |
8 |
Correct |
69 ms |
8064 KB |
Output is correct |
9 |
Correct |
69 ms |
8064 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
87 ms |
8312 KB |
Output is correct |
12 |
Correct |
99 ms |
8440 KB |
Output is correct |
13 |
Correct |
87 ms |
8312 KB |
Output is correct |
14 |
Correct |
85 ms |
8312 KB |
Output is correct |
15 |
Correct |
87 ms |
8320 KB |
Output is correct |
16 |
Correct |
93 ms |
8312 KB |
Output is correct |
17 |
Correct |
85 ms |
8312 KB |
Output is correct |
18 |
Correct |
62 ms |
8312 KB |
Output is correct |
19 |
Correct |
60 ms |
8320 KB |
Output is correct |
20 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
4 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
4 ms |
384 KB |
Output is correct |
11 |
Correct |
10 ms |
768 KB |
Output is correct |
12 |
Correct |
9 ms |
896 KB |
Output is correct |
13 |
Correct |
9 ms |
768 KB |
Output is correct |
14 |
Correct |
9 ms |
768 KB |
Output is correct |
15 |
Correct |
9 ms |
896 KB |
Output is correct |
16 |
Correct |
12 ms |
768 KB |
Output is correct |
17 |
Correct |
9 ms |
896 KB |
Output is correct |
18 |
Correct |
9 ms |
768 KB |
Output is correct |
19 |
Correct |
8 ms |
640 KB |
Output is correct |
20 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
79 ms |
8184 KB |
Output is correct |
2 |
Correct |
72 ms |
8060 KB |
Output is correct |
3 |
Correct |
72 ms |
8056 KB |
Output is correct |
4 |
Correct |
71 ms |
8064 KB |
Output is correct |
5 |
Correct |
70 ms |
8056 KB |
Output is correct |
6 |
Correct |
77 ms |
8056 KB |
Output is correct |
7 |
Correct |
74 ms |
8064 KB |
Output is correct |
8 |
Correct |
69 ms |
8064 KB |
Output is correct |
9 |
Correct |
69 ms |
8064 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
87 ms |
8312 KB |
Output is correct |
12 |
Correct |
99 ms |
8440 KB |
Output is correct |
13 |
Correct |
87 ms |
8312 KB |
Output is correct |
14 |
Correct |
85 ms |
8312 KB |
Output is correct |
15 |
Correct |
87 ms |
8320 KB |
Output is correct |
16 |
Correct |
93 ms |
8312 KB |
Output is correct |
17 |
Correct |
85 ms |
8312 KB |
Output is correct |
18 |
Correct |
62 ms |
8312 KB |
Output is correct |
19 |
Correct |
60 ms |
8320 KB |
Output is correct |
20 |
Correct |
5 ms |
384 KB |
Output is correct |
21 |
Correct |
137 ms |
9592 KB |
Output is correct |
22 |
Correct |
136 ms |
9464 KB |
Output is correct |
23 |
Correct |
138 ms |
9464 KB |
Output is correct |
24 |
Correct |
138 ms |
9596 KB |
Output is correct |
25 |
Correct |
142 ms |
9464 KB |
Output is correct |
26 |
Correct |
136 ms |
9592 KB |
Output is correct |
27 |
Correct |
138 ms |
9592 KB |
Output is correct |
28 |
Correct |
85 ms |
9464 KB |
Output is correct |
29 |
Correct |
85 ms |
9464 KB |
Output is correct |
30 |
Correct |
4 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
117 ms |
14072 KB |
Output is correct |
3 |
Correct |
118 ms |
14204 KB |
Output is correct |
4 |
Correct |
114 ms |
14076 KB |
Output is correct |
5 |
Correct |
115 ms |
14200 KB |
Output is correct |
6 |
Correct |
120 ms |
14196 KB |
Output is correct |
7 |
Correct |
133 ms |
14088 KB |
Output is correct |
8 |
Correct |
116 ms |
14072 KB |
Output is correct |
9 |
Correct |
115 ms |
13432 KB |
Output is correct |
10 |
Correct |
116 ms |
13560 KB |
Output is correct |
11 |
Correct |
79 ms |
8184 KB |
Output is correct |
12 |
Correct |
72 ms |
8060 KB |
Output is correct |
13 |
Correct |
72 ms |
8056 KB |
Output is correct |
14 |
Correct |
71 ms |
8064 KB |
Output is correct |
15 |
Correct |
70 ms |
8056 KB |
Output is correct |
16 |
Correct |
77 ms |
8056 KB |
Output is correct |
17 |
Correct |
74 ms |
8064 KB |
Output is correct |
18 |
Correct |
69 ms |
8064 KB |
Output is correct |
19 |
Correct |
69 ms |
8064 KB |
Output is correct |
20 |
Correct |
5 ms |
384 KB |
Output is correct |
21 |
Correct |
87 ms |
8312 KB |
Output is correct |
22 |
Correct |
99 ms |
8440 KB |
Output is correct |
23 |
Correct |
87 ms |
8312 KB |
Output is correct |
24 |
Correct |
85 ms |
8312 KB |
Output is correct |
25 |
Correct |
87 ms |
8320 KB |
Output is correct |
26 |
Correct |
93 ms |
8312 KB |
Output is correct |
27 |
Correct |
85 ms |
8312 KB |
Output is correct |
28 |
Correct |
62 ms |
8312 KB |
Output is correct |
29 |
Correct |
60 ms |
8320 KB |
Output is correct |
30 |
Correct |
5 ms |
384 KB |
Output is correct |
31 |
Correct |
5 ms |
384 KB |
Output is correct |
32 |
Correct |
5 ms |
384 KB |
Output is correct |
33 |
Correct |
5 ms |
384 KB |
Output is correct |
34 |
Correct |
5 ms |
384 KB |
Output is correct |
35 |
Correct |
5 ms |
384 KB |
Output is correct |
36 |
Correct |
5 ms |
384 KB |
Output is correct |
37 |
Correct |
5 ms |
384 KB |
Output is correct |
38 |
Correct |
5 ms |
384 KB |
Output is correct |
39 |
Correct |
5 ms |
384 KB |
Output is correct |
40 |
Correct |
4 ms |
384 KB |
Output is correct |
41 |
Correct |
10 ms |
768 KB |
Output is correct |
42 |
Correct |
9 ms |
896 KB |
Output is correct |
43 |
Correct |
9 ms |
768 KB |
Output is correct |
44 |
Correct |
9 ms |
768 KB |
Output is correct |
45 |
Correct |
9 ms |
896 KB |
Output is correct |
46 |
Correct |
12 ms |
768 KB |
Output is correct |
47 |
Correct |
9 ms |
896 KB |
Output is correct |
48 |
Correct |
9 ms |
768 KB |
Output is correct |
49 |
Correct |
8 ms |
640 KB |
Output is correct |
50 |
Correct |
5 ms |
384 KB |
Output is correct |
51 |
Correct |
137 ms |
9592 KB |
Output is correct |
52 |
Correct |
136 ms |
9464 KB |
Output is correct |
53 |
Correct |
138 ms |
9464 KB |
Output is correct |
54 |
Correct |
138 ms |
9596 KB |
Output is correct |
55 |
Correct |
142 ms |
9464 KB |
Output is correct |
56 |
Correct |
136 ms |
9592 KB |
Output is correct |
57 |
Correct |
138 ms |
9592 KB |
Output is correct |
58 |
Correct |
85 ms |
9464 KB |
Output is correct |
59 |
Correct |
85 ms |
9464 KB |
Output is correct |
60 |
Correct |
4 ms |
384 KB |
Output is correct |
61 |
Correct |
189 ms |
14216 KB |
Output is correct |
62 |
Correct |
180 ms |
14216 KB |
Output is correct |
63 |
Correct |
178 ms |
14072 KB |
Output is correct |
64 |
Correct |
180 ms |
14072 KB |
Output is correct |
65 |
Correct |
178 ms |
14072 KB |
Output is correct |
66 |
Correct |
181 ms |
14072 KB |
Output is correct |
67 |
Correct |
180 ms |
14072 KB |
Output is correct |
68 |
Correct |
181 ms |
13576 KB |
Output is correct |
69 |
Correct |
141 ms |
9720 KB |
Output is correct |
70 |
Correct |
5 ms |
384 KB |
Output is correct |