#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int n;
long long low[300001],high[300001];
long long ans = 0;
long long a[300001];
void ulow(int x){
for(;x<=n;x += x&-x){
low[x]++;
}
}
long long glow(int x){
long long s = 0;
for(;x;x -= x&-x){
s += low[x];
}
return s;
}
void uhigh(int x,long long v){
for(;x;x -= x&-x){
high[x]+=v;
}
}
long long ghigh(int x){
long long s = 0;
for(;x<=n;x += x&-x){
s += high[x];
}
return s;
}
int main(int argc,const char** argv){
cin >> n;
for(int i = 0;i < n;i++) cin >> a[i];
vector<long long> r(a,a+n);
sort(r.begin(),r.end());
r.resize(unique(r.begin(),r.end()) - r.begin());
for(int i = 0;i < n;i++) a[i] = lower_bound(r.begin(),r.end(),a[i]) - r.begin() + 1;
for(int i = 0;i < n;i++){
long long u = glow(a[i]-1);
ulow(a[i]);
long long v = ghigh(a[i]+1);
uhigh(a[i],u);
ans += v;
}
cout << ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
303 ms |
15192 KB |
Output is correct |
3 |
Correct |
256 ms |
15220 KB |
Output is correct |
4 |
Correct |
254 ms |
15220 KB |
Output is correct |
5 |
Correct |
253 ms |
15280 KB |
Output is correct |
6 |
Correct |
251 ms |
15172 KB |
Output is correct |
7 |
Correct |
284 ms |
15220 KB |
Output is correct |
8 |
Correct |
265 ms |
15212 KB |
Output is correct |
9 |
Correct |
255 ms |
12912 KB |
Output is correct |
10 |
Correct |
264 ms |
13072 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
86 ms |
5596 KB |
Output is correct |
2 |
Correct |
92 ms |
5636 KB |
Output is correct |
3 |
Correct |
85 ms |
5580 KB |
Output is correct |
4 |
Correct |
86 ms |
5628 KB |
Output is correct |
5 |
Correct |
88 ms |
5568 KB |
Output is correct |
6 |
Correct |
86 ms |
5512 KB |
Output is correct |
7 |
Correct |
88 ms |
5572 KB |
Output is correct |
8 |
Correct |
83 ms |
5624 KB |
Output is correct |
9 |
Correct |
93 ms |
5600 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
86 ms |
5596 KB |
Output is correct |
2 |
Correct |
92 ms |
5636 KB |
Output is correct |
3 |
Correct |
85 ms |
5580 KB |
Output is correct |
4 |
Correct |
86 ms |
5628 KB |
Output is correct |
5 |
Correct |
88 ms |
5568 KB |
Output is correct |
6 |
Correct |
86 ms |
5512 KB |
Output is correct |
7 |
Correct |
88 ms |
5572 KB |
Output is correct |
8 |
Correct |
83 ms |
5624 KB |
Output is correct |
9 |
Correct |
93 ms |
5600 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
113 ms |
5892 KB |
Output is correct |
12 |
Correct |
122 ms |
5804 KB |
Output is correct |
13 |
Correct |
113 ms |
5904 KB |
Output is correct |
14 |
Correct |
112 ms |
5828 KB |
Output is correct |
15 |
Correct |
113 ms |
5828 KB |
Output is correct |
16 |
Correct |
113 ms |
5836 KB |
Output is correct |
17 |
Correct |
114 ms |
5832 KB |
Output is correct |
18 |
Correct |
90 ms |
5836 KB |
Output is correct |
19 |
Correct |
88 ms |
5840 KB |
Output is correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
10 ms |
808 KB |
Output is correct |
12 |
Correct |
10 ms |
768 KB |
Output is correct |
13 |
Correct |
10 ms |
784 KB |
Output is correct |
14 |
Correct |
10 ms |
696 KB |
Output is correct |
15 |
Correct |
10 ms |
696 KB |
Output is correct |
16 |
Correct |
10 ms |
764 KB |
Output is correct |
17 |
Correct |
10 ms |
696 KB |
Output is correct |
18 |
Correct |
10 ms |
716 KB |
Output is correct |
19 |
Correct |
5 ms |
460 KB |
Output is correct |
20 |
Correct |
0 ms |
300 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
86 ms |
5596 KB |
Output is correct |
2 |
Correct |
92 ms |
5636 KB |
Output is correct |
3 |
Correct |
85 ms |
5580 KB |
Output is correct |
4 |
Correct |
86 ms |
5628 KB |
Output is correct |
5 |
Correct |
88 ms |
5568 KB |
Output is correct |
6 |
Correct |
86 ms |
5512 KB |
Output is correct |
7 |
Correct |
88 ms |
5572 KB |
Output is correct |
8 |
Correct |
83 ms |
5624 KB |
Output is correct |
9 |
Correct |
93 ms |
5600 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
113 ms |
5892 KB |
Output is correct |
12 |
Correct |
122 ms |
5804 KB |
Output is correct |
13 |
Correct |
113 ms |
5904 KB |
Output is correct |
14 |
Correct |
112 ms |
5828 KB |
Output is correct |
15 |
Correct |
113 ms |
5828 KB |
Output is correct |
16 |
Correct |
113 ms |
5836 KB |
Output is correct |
17 |
Correct |
114 ms |
5832 KB |
Output is correct |
18 |
Correct |
90 ms |
5836 KB |
Output is correct |
19 |
Correct |
88 ms |
5840 KB |
Output is correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |
21 |
Correct |
192 ms |
8128 KB |
Output is correct |
22 |
Correct |
189 ms |
8132 KB |
Output is correct |
23 |
Correct |
216 ms |
8128 KB |
Output is correct |
24 |
Correct |
186 ms |
8168 KB |
Output is correct |
25 |
Correct |
188 ms |
8220 KB |
Output is correct |
26 |
Correct |
188 ms |
8132 KB |
Output is correct |
27 |
Correct |
188 ms |
8128 KB |
Output is correct |
28 |
Correct |
129 ms |
8132 KB |
Output is correct |
29 |
Correct |
152 ms |
8160 KB |
Output is correct |
30 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
303 ms |
15192 KB |
Output is correct |
3 |
Correct |
256 ms |
15220 KB |
Output is correct |
4 |
Correct |
254 ms |
15220 KB |
Output is correct |
5 |
Correct |
253 ms |
15280 KB |
Output is correct |
6 |
Correct |
251 ms |
15172 KB |
Output is correct |
7 |
Correct |
284 ms |
15220 KB |
Output is correct |
8 |
Correct |
265 ms |
15212 KB |
Output is correct |
9 |
Correct |
255 ms |
12912 KB |
Output is correct |
10 |
Correct |
264 ms |
13072 KB |
Output is correct |
11 |
Correct |
86 ms |
5596 KB |
Output is correct |
12 |
Correct |
92 ms |
5636 KB |
Output is correct |
13 |
Correct |
85 ms |
5580 KB |
Output is correct |
14 |
Correct |
86 ms |
5628 KB |
Output is correct |
15 |
Correct |
88 ms |
5568 KB |
Output is correct |
16 |
Correct |
86 ms |
5512 KB |
Output is correct |
17 |
Correct |
88 ms |
5572 KB |
Output is correct |
18 |
Correct |
83 ms |
5624 KB |
Output is correct |
19 |
Correct |
93 ms |
5600 KB |
Output is correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |
21 |
Correct |
113 ms |
5892 KB |
Output is correct |
22 |
Correct |
122 ms |
5804 KB |
Output is correct |
23 |
Correct |
113 ms |
5904 KB |
Output is correct |
24 |
Correct |
112 ms |
5828 KB |
Output is correct |
25 |
Correct |
113 ms |
5828 KB |
Output is correct |
26 |
Correct |
113 ms |
5836 KB |
Output is correct |
27 |
Correct |
114 ms |
5832 KB |
Output is correct |
28 |
Correct |
90 ms |
5836 KB |
Output is correct |
29 |
Correct |
88 ms |
5840 KB |
Output is correct |
30 |
Correct |
1 ms |
204 KB |
Output is correct |
31 |
Correct |
1 ms |
332 KB |
Output is correct |
32 |
Correct |
1 ms |
332 KB |
Output is correct |
33 |
Correct |
1 ms |
332 KB |
Output is correct |
34 |
Correct |
1 ms |
332 KB |
Output is correct |
35 |
Correct |
1 ms |
332 KB |
Output is correct |
36 |
Correct |
1 ms |
332 KB |
Output is correct |
37 |
Correct |
1 ms |
332 KB |
Output is correct |
38 |
Correct |
1 ms |
332 KB |
Output is correct |
39 |
Correct |
1 ms |
204 KB |
Output is correct |
40 |
Correct |
1 ms |
204 KB |
Output is correct |
41 |
Correct |
10 ms |
808 KB |
Output is correct |
42 |
Correct |
10 ms |
768 KB |
Output is correct |
43 |
Correct |
10 ms |
784 KB |
Output is correct |
44 |
Correct |
10 ms |
696 KB |
Output is correct |
45 |
Correct |
10 ms |
696 KB |
Output is correct |
46 |
Correct |
10 ms |
764 KB |
Output is correct |
47 |
Correct |
10 ms |
696 KB |
Output is correct |
48 |
Correct |
10 ms |
716 KB |
Output is correct |
49 |
Correct |
5 ms |
460 KB |
Output is correct |
50 |
Correct |
0 ms |
300 KB |
Output is correct |
51 |
Correct |
192 ms |
8128 KB |
Output is correct |
52 |
Correct |
189 ms |
8132 KB |
Output is correct |
53 |
Correct |
216 ms |
8128 KB |
Output is correct |
54 |
Correct |
186 ms |
8168 KB |
Output is correct |
55 |
Correct |
188 ms |
8220 KB |
Output is correct |
56 |
Correct |
188 ms |
8132 KB |
Output is correct |
57 |
Correct |
188 ms |
8128 KB |
Output is correct |
58 |
Correct |
129 ms |
8132 KB |
Output is correct |
59 |
Correct |
152 ms |
8160 KB |
Output is correct |
60 |
Correct |
1 ms |
204 KB |
Output is correct |
61 |
Correct |
333 ms |
15148 KB |
Output is correct |
62 |
Correct |
322 ms |
15196 KB |
Output is correct |
63 |
Correct |
337 ms |
15276 KB |
Output is correct |
64 |
Correct |
354 ms |
15148 KB |
Output is correct |
65 |
Correct |
322 ms |
15220 KB |
Output is correct |
66 |
Correct |
352 ms |
15140 KB |
Output is correct |
67 |
Correct |
317 ms |
15180 KB |
Output is correct |
68 |
Correct |
319 ms |
13044 KB |
Output is correct |
69 |
Correct |
190 ms |
8756 KB |
Output is correct |
70 |
Correct |
1 ms |
204 KB |
Output is correct |