#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;
}
int st[NMAX], n, dr[NMAX];
int aib[NMAX + 5];
void update(int x, int val){
for(int i = x; i <= n; i += i&(-i))
aib[i] += val;
}
int query(int x){
int val = 0;
for(int 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);
int i;
cin >> n;
for(i = 1; i <= n; i++){
cin >> v[i].i;
v[i].idx = i;
}
int 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 |
149 ms |
10860 KB |
Output is correct |
3 |
Correct |
148 ms |
10860 KB |
Output is correct |
4 |
Correct |
152 ms |
10860 KB |
Output is correct |
5 |
Correct |
148 ms |
10860 KB |
Output is correct |
6 |
Correct |
149 ms |
10860 KB |
Output is correct |
7 |
Correct |
153 ms |
10860 KB |
Output is correct |
8 |
Correct |
201 ms |
10860 KB |
Output is correct |
9 |
Correct |
148 ms |
10308 KB |
Output is correct |
10 |
Correct |
150 ms |
10476 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
146 ms |
9752 KB |
Output is correct |
2 |
Correct |
141 ms |
9708 KB |
Output is correct |
3 |
Correct |
142 ms |
9708 KB |
Output is correct |
4 |
Correct |
143 ms |
9836 KB |
Output is correct |
5 |
Correct |
144 ms |
9708 KB |
Output is correct |
6 |
Correct |
141 ms |
9836 KB |
Output is correct |
7 |
Correct |
141 ms |
9708 KB |
Output is correct |
8 |
Correct |
136 ms |
9708 KB |
Output is correct |
9 |
Correct |
134 ms |
9708 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
146 ms |
9752 KB |
Output is correct |
2 |
Correct |
141 ms |
9708 KB |
Output is correct |
3 |
Correct |
142 ms |
9708 KB |
Output is correct |
4 |
Correct |
143 ms |
9836 KB |
Output is correct |
5 |
Correct |
144 ms |
9708 KB |
Output is correct |
6 |
Correct |
141 ms |
9836 KB |
Output is correct |
7 |
Correct |
141 ms |
9708 KB |
Output is correct |
8 |
Correct |
136 ms |
9708 KB |
Output is correct |
9 |
Correct |
134 ms |
9708 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
154 ms |
9708 KB |
Output is correct |
12 |
Correct |
155 ms |
9816 KB |
Output is correct |
13 |
Correct |
156 ms |
9708 KB |
Output is correct |
14 |
Correct |
155 ms |
9708 KB |
Output is correct |
15 |
Correct |
154 ms |
9836 KB |
Output is correct |
16 |
Correct |
157 ms |
9708 KB |
Output is correct |
17 |
Correct |
157 ms |
9836 KB |
Output is correct |
18 |
Correct |
117 ms |
9708 KB |
Output is correct |
19 |
Correct |
119 ms |
9708 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 |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
0 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 |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
0 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 |
6 ms |
748 KB |
Output is correct |
12 |
Correct |
6 ms |
748 KB |
Output is correct |
13 |
Correct |
6 ms |
748 KB |
Output is correct |
14 |
Correct |
6 ms |
748 KB |
Output is correct |
15 |
Correct |
6 ms |
748 KB |
Output is correct |
16 |
Correct |
6 ms |
748 KB |
Output is correct |
17 |
Correct |
6 ms |
748 KB |
Output is correct |
18 |
Correct |
6 ms |
748 KB |
Output is correct |
19 |
Correct |
5 ms |
748 KB |
Output is correct |
20 |
Correct |
0 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
146 ms |
9752 KB |
Output is correct |
2 |
Correct |
141 ms |
9708 KB |
Output is correct |
3 |
Correct |
142 ms |
9708 KB |
Output is correct |
4 |
Correct |
143 ms |
9836 KB |
Output is correct |
5 |
Correct |
144 ms |
9708 KB |
Output is correct |
6 |
Correct |
141 ms |
9836 KB |
Output is correct |
7 |
Correct |
141 ms |
9708 KB |
Output is correct |
8 |
Correct |
136 ms |
9708 KB |
Output is correct |
9 |
Correct |
134 ms |
9708 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
154 ms |
9708 KB |
Output is correct |
12 |
Correct |
155 ms |
9816 KB |
Output is correct |
13 |
Correct |
156 ms |
9708 KB |
Output is correct |
14 |
Correct |
155 ms |
9708 KB |
Output is correct |
15 |
Correct |
154 ms |
9836 KB |
Output is correct |
16 |
Correct |
157 ms |
9708 KB |
Output is correct |
17 |
Correct |
157 ms |
9836 KB |
Output is correct |
18 |
Correct |
117 ms |
9708 KB |
Output is correct |
19 |
Correct |
119 ms |
9708 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
21 |
Correct |
174 ms |
10140 KB |
Output is correct |
22 |
Correct |
177 ms |
10220 KB |
Output is correct |
23 |
Correct |
171 ms |
10092 KB |
Output is correct |
24 |
Correct |
173 ms |
10220 KB |
Output is correct |
25 |
Correct |
175 ms |
10220 KB |
Output is correct |
26 |
Correct |
172 ms |
10092 KB |
Output is correct |
27 |
Correct |
172 ms |
10220 KB |
Output is correct |
28 |
Correct |
117 ms |
10220 KB |
Output is correct |
29 |
Correct |
118 ms |
10220 KB |
Output is correct |
30 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
149 ms |
10860 KB |
Output is correct |
3 |
Correct |
148 ms |
10860 KB |
Output is correct |
4 |
Correct |
152 ms |
10860 KB |
Output is correct |
5 |
Correct |
148 ms |
10860 KB |
Output is correct |
6 |
Correct |
149 ms |
10860 KB |
Output is correct |
7 |
Correct |
153 ms |
10860 KB |
Output is correct |
8 |
Correct |
201 ms |
10860 KB |
Output is correct |
9 |
Correct |
148 ms |
10308 KB |
Output is correct |
10 |
Correct |
150 ms |
10476 KB |
Output is correct |
11 |
Correct |
146 ms |
9752 KB |
Output is correct |
12 |
Correct |
141 ms |
9708 KB |
Output is correct |
13 |
Correct |
142 ms |
9708 KB |
Output is correct |
14 |
Correct |
143 ms |
9836 KB |
Output is correct |
15 |
Correct |
144 ms |
9708 KB |
Output is correct |
16 |
Correct |
141 ms |
9836 KB |
Output is correct |
17 |
Correct |
141 ms |
9708 KB |
Output is correct |
18 |
Correct |
136 ms |
9708 KB |
Output is correct |
19 |
Correct |
134 ms |
9708 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
21 |
Correct |
154 ms |
9708 KB |
Output is correct |
22 |
Correct |
155 ms |
9816 KB |
Output is correct |
23 |
Correct |
156 ms |
9708 KB |
Output is correct |
24 |
Correct |
155 ms |
9708 KB |
Output is correct |
25 |
Correct |
154 ms |
9836 KB |
Output is correct |
26 |
Correct |
157 ms |
9708 KB |
Output is correct |
27 |
Correct |
157 ms |
9836 KB |
Output is correct |
28 |
Correct |
117 ms |
9708 KB |
Output is correct |
29 |
Correct |
119 ms |
9708 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 |
364 KB |
Output is correct |
37 |
Correct |
1 ms |
364 KB |
Output is correct |
38 |
Correct |
0 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 |
6 ms |
748 KB |
Output is correct |
42 |
Correct |
6 ms |
748 KB |
Output is correct |
43 |
Correct |
6 ms |
748 KB |
Output is correct |
44 |
Correct |
6 ms |
748 KB |
Output is correct |
45 |
Correct |
6 ms |
748 KB |
Output is correct |
46 |
Correct |
6 ms |
748 KB |
Output is correct |
47 |
Correct |
6 ms |
748 KB |
Output is correct |
48 |
Correct |
6 ms |
748 KB |
Output is correct |
49 |
Correct |
5 ms |
748 KB |
Output is correct |
50 |
Correct |
0 ms |
364 KB |
Output is correct |
51 |
Correct |
174 ms |
10140 KB |
Output is correct |
52 |
Correct |
177 ms |
10220 KB |
Output is correct |
53 |
Correct |
171 ms |
10092 KB |
Output is correct |
54 |
Correct |
173 ms |
10220 KB |
Output is correct |
55 |
Correct |
175 ms |
10220 KB |
Output is correct |
56 |
Correct |
172 ms |
10092 KB |
Output is correct |
57 |
Correct |
172 ms |
10220 KB |
Output is correct |
58 |
Correct |
117 ms |
10220 KB |
Output is correct |
59 |
Correct |
118 ms |
10220 KB |
Output is correct |
60 |
Correct |
1 ms |
364 KB |
Output is correct |
61 |
Correct |
233 ms |
10988 KB |
Output is correct |
62 |
Correct |
236 ms |
10860 KB |
Output is correct |
63 |
Correct |
201 ms |
10860 KB |
Output is correct |
64 |
Correct |
207 ms |
11016 KB |
Output is correct |
65 |
Correct |
202 ms |
10860 KB |
Output is correct |
66 |
Correct |
204 ms |
10988 KB |
Output is correct |
67 |
Correct |
206 ms |
10988 KB |
Output is correct |
68 |
Correct |
204 ms |
10348 KB |
Output is correct |
69 |
Correct |
176 ms |
10272 KB |
Output is correct |
70 |
Correct |
1 ms |
364 KB |
Output is correct |