#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define debug(x) cerr << #x << " " << x << "\n"
#define debug_with_space(x) cerr << #x << " " << x << " "
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair <ll, ll> pii;
typedef pair <ll, pii> piii;
typedef tree <pii, null_type, less <pii>, rb_tree_tag, tree_order_statistics_node_update> OST;
const ll NMAX = 300001;
const ll INF = 1e9;
const ll MOD = 1000000007;
const ll BLOCK = 101;
const ll nr_of_bits = 35;
struct ura{
ll i, v, idx;
} v[NMAX];
bool cmp(ura a, ura b){
return a.i < b.i;
}
bool cmpp(ura a, ura b){
return a.idx < b.idx;
}
ll st[NMAX], n, dr[NMAX];
ll aib[NMAX + 5];
void update(ll x, ll val){
for(ll i = x; i <= n; i += i&(-i))
aib[i] += val;
}
ll query(ll x){
ll val = 0;
for(ll i = x; i > 0; i -= i&(-i))
val += aib[i];
return val;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
ll i;
cin >> n;
for(i = 1; i <= n; i++){
cin >> v[i].i;
v[i].idx = i;
}
ll cnt = 1;
sort(v + 1, v + n + 1, cmp);
for(i = 1; i <= n; i++){
if(i > 1 && v[i].i != v[i - 1].i)
cnt++;
v[i].v = cnt;
}
sort(v + 1, v + n + 1, cmpp);
for(i = 1; i <= n; i++){
update(v[i].v, 1);
st[i] = query(v[i].v - 1);
}
ll sol = 0;
for(i = 1; i <= n; i++){
update(v[i].v, -1);
}
for(i = n; i >= 1; i--){
update(v[i].v, 1);
dr[i] = query(v[i].v - 1);
sol += 1LL * st[i] * dr[i];
}
cout << sol;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
154 ms |
18128 KB |
Output is correct |
3 |
Correct |
156 ms |
18156 KB |
Output is correct |
4 |
Correct |
152 ms |
18156 KB |
Output is correct |
5 |
Correct |
153 ms |
18156 KB |
Output is correct |
6 |
Correct |
151 ms |
18156 KB |
Output is correct |
7 |
Correct |
151 ms |
18156 KB |
Output is correct |
8 |
Correct |
154 ms |
18156 KB |
Output is correct |
9 |
Correct |
158 ms |
17004 KB |
Output is correct |
10 |
Correct |
156 ms |
17004 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
155 ms |
12140 KB |
Output is correct |
2 |
Correct |
160 ms |
12140 KB |
Output is correct |
3 |
Correct |
158 ms |
12140 KB |
Output is correct |
4 |
Correct |
155 ms |
12140 KB |
Output is correct |
5 |
Correct |
156 ms |
12140 KB |
Output is correct |
6 |
Correct |
154 ms |
12140 KB |
Output is correct |
7 |
Correct |
154 ms |
12140 KB |
Output is correct |
8 |
Correct |
147 ms |
12140 KB |
Output is correct |
9 |
Correct |
149 ms |
12140 KB |
Output is correct |
10 |
Correct |
1 ms |
380 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
155 ms |
12140 KB |
Output is correct |
2 |
Correct |
160 ms |
12140 KB |
Output is correct |
3 |
Correct |
158 ms |
12140 KB |
Output is correct |
4 |
Correct |
155 ms |
12140 KB |
Output is correct |
5 |
Correct |
156 ms |
12140 KB |
Output is correct |
6 |
Correct |
154 ms |
12140 KB |
Output is correct |
7 |
Correct |
154 ms |
12140 KB |
Output is correct |
8 |
Correct |
147 ms |
12140 KB |
Output is correct |
9 |
Correct |
149 ms |
12140 KB |
Output is correct |
10 |
Correct |
1 ms |
380 KB |
Output is correct |
11 |
Correct |
167 ms |
12140 KB |
Output is correct |
12 |
Correct |
165 ms |
12140 KB |
Output is correct |
13 |
Correct |
163 ms |
12140 KB |
Output is correct |
14 |
Correct |
166 ms |
12140 KB |
Output is correct |
15 |
Correct |
164 ms |
12140 KB |
Output is correct |
16 |
Correct |
166 ms |
12268 KB |
Output is correct |
17 |
Correct |
167 ms |
12140 KB |
Output is correct |
18 |
Correct |
131 ms |
12140 KB |
Output is correct |
19 |
Correct |
132 ms |
12140 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
360 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
360 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
8 ms |
1004 KB |
Output is correct |
12 |
Correct |
7 ms |
1004 KB |
Output is correct |
13 |
Correct |
6 ms |
1004 KB |
Output is correct |
14 |
Correct |
6 ms |
1004 KB |
Output is correct |
15 |
Correct |
6 ms |
1004 KB |
Output is correct |
16 |
Correct |
6 ms |
1004 KB |
Output is correct |
17 |
Correct |
7 ms |
1004 KB |
Output is correct |
18 |
Correct |
6 ms |
1004 KB |
Output is correct |
19 |
Correct |
6 ms |
768 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
155 ms |
12140 KB |
Output is correct |
2 |
Correct |
160 ms |
12140 KB |
Output is correct |
3 |
Correct |
158 ms |
12140 KB |
Output is correct |
4 |
Correct |
155 ms |
12140 KB |
Output is correct |
5 |
Correct |
156 ms |
12140 KB |
Output is correct |
6 |
Correct |
154 ms |
12140 KB |
Output is correct |
7 |
Correct |
154 ms |
12140 KB |
Output is correct |
8 |
Correct |
147 ms |
12140 KB |
Output is correct |
9 |
Correct |
149 ms |
12140 KB |
Output is correct |
10 |
Correct |
1 ms |
380 KB |
Output is correct |
11 |
Correct |
167 ms |
12140 KB |
Output is correct |
12 |
Correct |
165 ms |
12140 KB |
Output is correct |
13 |
Correct |
163 ms |
12140 KB |
Output is correct |
14 |
Correct |
166 ms |
12140 KB |
Output is correct |
15 |
Correct |
164 ms |
12140 KB |
Output is correct |
16 |
Correct |
166 ms |
12268 KB |
Output is correct |
17 |
Correct |
167 ms |
12140 KB |
Output is correct |
18 |
Correct |
131 ms |
12140 KB |
Output is correct |
19 |
Correct |
132 ms |
12140 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
21 |
Correct |
179 ms |
12780 KB |
Output is correct |
22 |
Correct |
178 ms |
12780 KB |
Output is correct |
23 |
Correct |
180 ms |
12908 KB |
Output is correct |
24 |
Correct |
178 ms |
12780 KB |
Output is correct |
25 |
Correct |
178 ms |
12780 KB |
Output is correct |
26 |
Correct |
187 ms |
12780 KB |
Output is correct |
27 |
Correct |
185 ms |
12876 KB |
Output is correct |
28 |
Correct |
126 ms |
12908 KB |
Output is correct |
29 |
Correct |
123 ms |
12908 KB |
Output is correct |
30 |
Correct |
1 ms |
512 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
154 ms |
18128 KB |
Output is correct |
3 |
Correct |
156 ms |
18156 KB |
Output is correct |
4 |
Correct |
152 ms |
18156 KB |
Output is correct |
5 |
Correct |
153 ms |
18156 KB |
Output is correct |
6 |
Correct |
151 ms |
18156 KB |
Output is correct |
7 |
Correct |
151 ms |
18156 KB |
Output is correct |
8 |
Correct |
154 ms |
18156 KB |
Output is correct |
9 |
Correct |
158 ms |
17004 KB |
Output is correct |
10 |
Correct |
156 ms |
17004 KB |
Output is correct |
11 |
Correct |
155 ms |
12140 KB |
Output is correct |
12 |
Correct |
160 ms |
12140 KB |
Output is correct |
13 |
Correct |
158 ms |
12140 KB |
Output is correct |
14 |
Correct |
155 ms |
12140 KB |
Output is correct |
15 |
Correct |
156 ms |
12140 KB |
Output is correct |
16 |
Correct |
154 ms |
12140 KB |
Output is correct |
17 |
Correct |
154 ms |
12140 KB |
Output is correct |
18 |
Correct |
147 ms |
12140 KB |
Output is correct |
19 |
Correct |
149 ms |
12140 KB |
Output is correct |
20 |
Correct |
1 ms |
380 KB |
Output is correct |
21 |
Correct |
167 ms |
12140 KB |
Output is correct |
22 |
Correct |
165 ms |
12140 KB |
Output is correct |
23 |
Correct |
163 ms |
12140 KB |
Output is correct |
24 |
Correct |
166 ms |
12140 KB |
Output is correct |
25 |
Correct |
164 ms |
12140 KB |
Output is correct |
26 |
Correct |
166 ms |
12268 KB |
Output is correct |
27 |
Correct |
167 ms |
12140 KB |
Output is correct |
28 |
Correct |
131 ms |
12140 KB |
Output is correct |
29 |
Correct |
132 ms |
12140 KB |
Output is correct |
30 |
Correct |
1 ms |
364 KB |
Output is correct |
31 |
Correct |
1 ms |
364 KB |
Output is correct |
32 |
Correct |
1 ms |
364 KB |
Output is correct |
33 |
Correct |
1 ms |
364 KB |
Output is correct |
34 |
Correct |
1 ms |
364 KB |
Output is correct |
35 |
Correct |
1 ms |
364 KB |
Output is correct |
36 |
Correct |
1 ms |
360 KB |
Output is correct |
37 |
Correct |
1 ms |
364 KB |
Output is correct |
38 |
Correct |
1 ms |
364 KB |
Output is correct |
39 |
Correct |
1 ms |
364 KB |
Output is correct |
40 |
Correct |
1 ms |
364 KB |
Output is correct |
41 |
Correct |
8 ms |
1004 KB |
Output is correct |
42 |
Correct |
7 ms |
1004 KB |
Output is correct |
43 |
Correct |
6 ms |
1004 KB |
Output is correct |
44 |
Correct |
6 ms |
1004 KB |
Output is correct |
45 |
Correct |
6 ms |
1004 KB |
Output is correct |
46 |
Correct |
6 ms |
1004 KB |
Output is correct |
47 |
Correct |
7 ms |
1004 KB |
Output is correct |
48 |
Correct |
6 ms |
1004 KB |
Output is correct |
49 |
Correct |
6 ms |
768 KB |
Output is correct |
50 |
Correct |
1 ms |
364 KB |
Output is correct |
51 |
Correct |
179 ms |
12780 KB |
Output is correct |
52 |
Correct |
178 ms |
12780 KB |
Output is correct |
53 |
Correct |
180 ms |
12908 KB |
Output is correct |
54 |
Correct |
178 ms |
12780 KB |
Output is correct |
55 |
Correct |
178 ms |
12780 KB |
Output is correct |
56 |
Correct |
187 ms |
12780 KB |
Output is correct |
57 |
Correct |
185 ms |
12876 KB |
Output is correct |
58 |
Correct |
126 ms |
12908 KB |
Output is correct |
59 |
Correct |
123 ms |
12908 KB |
Output is correct |
60 |
Correct |
1 ms |
512 KB |
Output is correct |
61 |
Correct |
210 ms |
18156 KB |
Output is correct |
62 |
Correct |
212 ms |
18156 KB |
Output is correct |
63 |
Correct |
213 ms |
18156 KB |
Output is correct |
64 |
Correct |
211 ms |
18156 KB |
Output is correct |
65 |
Correct |
212 ms |
18204 KB |
Output is correct |
66 |
Correct |
209 ms |
18156 KB |
Output is correct |
67 |
Correct |
215 ms |
18156 KB |
Output is correct |
68 |
Correct |
211 ms |
17004 KB |
Output is correct |
69 |
Correct |
183 ms |
14956 KB |
Output is correct |
70 |
Correct |
1 ms |
364 KB |
Output is correct |