#include<bits/stdc++.h>
using namespace std;
struct nodo{
int s, e, m, cnt;
nodo *l, *r;
nodo(int s1, int e1){
s=s1, e=e1, m=(s1+e1)/2, cnt=0;
if(s == e) return;
l = new nodo(s, m);
r = new nodo(m+1, e);
}
void update(int x, int v){
cnt += v;
if(s == e) return;
if(x <= m) l->update(x, v);
else r->update(x, v);
}
int query(int x, int y){
if(x <= s && y >= e) return cnt;
int ret = 0;
if(x <= m) ret += l->query(x, y);
if(y >= m+1) ret += r->query(x, y);
return ret;
}
void clear(){
cnt = 0;
if(s == e) return;
l->clear();
r->clear();
}
};
int main(){
long n;
cin>>n;
long long H[n+1];
for(int i=1; i<=n; i++){
cin>>H[i];
}
long long izquierda[n+1], derecha[n+1];
pair<long long, int> arreglo[n+1];
int cnt = 1;
long long total = 0;
for(int i=1; i<=n; i++){
arreglo[i] = {H[i], i};
}
sort(arreglo + 1, arreglo + n + 1);
for(int i=1; i<=n; i++){
if(i>1 and arreglo[i].first != arreglo[i-1].first){
cnt++;
}
H[arreglo[i].second] = cnt;
}
nodo *algo = new nodo(0, n);
for(int i=1; i<=n; i++){
izquierda[i] = algo->query(0, H[i] - 1);
algo->update(H[i], 1);
}
algo->clear();
for(int i=n; i>0; i--){
derecha[i] = algo->query(0, H[i] - 1);
algo->update(H[i], 1);
}
for(int i=1; i<=n; i++){
total += izquierda[i] * derecha[i];
}
cout<<total;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
323 ms |
40120 KB |
Output is correct |
3 |
Correct |
325 ms |
40192 KB |
Output is correct |
4 |
Correct |
411 ms |
40128 KB |
Output is correct |
5 |
Correct |
325 ms |
40124 KB |
Output is correct |
6 |
Correct |
376 ms |
40192 KB |
Output is correct |
7 |
Correct |
317 ms |
40136 KB |
Output is correct |
8 |
Correct |
343 ms |
40120 KB |
Output is correct |
9 |
Correct |
334 ms |
40124 KB |
Output is correct |
10 |
Correct |
335 ms |
40140 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
213 ms |
40188 KB |
Output is correct |
2 |
Correct |
186 ms |
40192 KB |
Output is correct |
3 |
Correct |
203 ms |
40120 KB |
Output is correct |
4 |
Correct |
211 ms |
40120 KB |
Output is correct |
5 |
Correct |
178 ms |
40144 KB |
Output is correct |
6 |
Correct |
181 ms |
40140 KB |
Output is correct |
7 |
Correct |
184 ms |
40192 KB |
Output is correct |
8 |
Correct |
211 ms |
40120 KB |
Output is correct |
9 |
Correct |
160 ms |
40188 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
213 ms |
40188 KB |
Output is correct |
2 |
Correct |
186 ms |
40192 KB |
Output is correct |
3 |
Correct |
203 ms |
40120 KB |
Output is correct |
4 |
Correct |
211 ms |
40120 KB |
Output is correct |
5 |
Correct |
178 ms |
40144 KB |
Output is correct |
6 |
Correct |
181 ms |
40140 KB |
Output is correct |
7 |
Correct |
184 ms |
40192 KB |
Output is correct |
8 |
Correct |
211 ms |
40120 KB |
Output is correct |
9 |
Correct |
160 ms |
40188 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
217 ms |
40192 KB |
Output is correct |
12 |
Correct |
233 ms |
40268 KB |
Output is correct |
13 |
Correct |
219 ms |
40192 KB |
Output is correct |
14 |
Correct |
223 ms |
40200 KB |
Output is correct |
15 |
Correct |
234 ms |
40136 KB |
Output is correct |
16 |
Correct |
216 ms |
40192 KB |
Output is correct |
17 |
Correct |
214 ms |
40144 KB |
Output is correct |
18 |
Correct |
169 ms |
40264 KB |
Output is correct |
19 |
Correct |
222 ms |
40128 KB |
Output is correct |
20 |
Correct |
1 ms |
256 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 |
340 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 |
1 ms |
340 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 |
340 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 |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
14 ms |
1620 KB |
Output is correct |
12 |
Correct |
18 ms |
1580 KB |
Output is correct |
13 |
Correct |
15 ms |
1576 KB |
Output is correct |
14 |
Correct |
14 ms |
1620 KB |
Output is correct |
15 |
Correct |
13 ms |
1620 KB |
Output is correct |
16 |
Correct |
12 ms |
1620 KB |
Output is correct |
17 |
Correct |
14 ms |
1520 KB |
Output is correct |
18 |
Correct |
12 ms |
1620 KB |
Output is correct |
19 |
Correct |
8 ms |
1620 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
213 ms |
40188 KB |
Output is correct |
2 |
Correct |
186 ms |
40192 KB |
Output is correct |
3 |
Correct |
203 ms |
40120 KB |
Output is correct |
4 |
Correct |
211 ms |
40120 KB |
Output is correct |
5 |
Correct |
178 ms |
40144 KB |
Output is correct |
6 |
Correct |
181 ms |
40140 KB |
Output is correct |
7 |
Correct |
184 ms |
40192 KB |
Output is correct |
8 |
Correct |
211 ms |
40120 KB |
Output is correct |
9 |
Correct |
160 ms |
40188 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
217 ms |
40192 KB |
Output is correct |
12 |
Correct |
233 ms |
40268 KB |
Output is correct |
13 |
Correct |
219 ms |
40192 KB |
Output is correct |
14 |
Correct |
223 ms |
40200 KB |
Output is correct |
15 |
Correct |
234 ms |
40136 KB |
Output is correct |
16 |
Correct |
216 ms |
40192 KB |
Output is correct |
17 |
Correct |
214 ms |
40144 KB |
Output is correct |
18 |
Correct |
169 ms |
40264 KB |
Output is correct |
19 |
Correct |
222 ms |
40128 KB |
Output is correct |
20 |
Correct |
1 ms |
256 KB |
Output is correct |
21 |
Correct |
468 ms |
40140 KB |
Output is correct |
22 |
Correct |
362 ms |
40108 KB |
Output is correct |
23 |
Correct |
401 ms |
40188 KB |
Output is correct |
24 |
Correct |
387 ms |
40200 KB |
Output is correct |
25 |
Correct |
452 ms |
40260 KB |
Output is correct |
26 |
Correct |
387 ms |
40252 KB |
Output is correct |
27 |
Correct |
428 ms |
40188 KB |
Output is correct |
28 |
Correct |
205 ms |
40196 KB |
Output is correct |
29 |
Correct |
204 ms |
40192 KB |
Output is correct |
30 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
323 ms |
40120 KB |
Output is correct |
3 |
Correct |
325 ms |
40192 KB |
Output is correct |
4 |
Correct |
411 ms |
40128 KB |
Output is correct |
5 |
Correct |
325 ms |
40124 KB |
Output is correct |
6 |
Correct |
376 ms |
40192 KB |
Output is correct |
7 |
Correct |
317 ms |
40136 KB |
Output is correct |
8 |
Correct |
343 ms |
40120 KB |
Output is correct |
9 |
Correct |
334 ms |
40124 KB |
Output is correct |
10 |
Correct |
335 ms |
40140 KB |
Output is correct |
11 |
Correct |
213 ms |
40188 KB |
Output is correct |
12 |
Correct |
186 ms |
40192 KB |
Output is correct |
13 |
Correct |
203 ms |
40120 KB |
Output is correct |
14 |
Correct |
211 ms |
40120 KB |
Output is correct |
15 |
Correct |
178 ms |
40144 KB |
Output is correct |
16 |
Correct |
181 ms |
40140 KB |
Output is correct |
17 |
Correct |
184 ms |
40192 KB |
Output is correct |
18 |
Correct |
211 ms |
40120 KB |
Output is correct |
19 |
Correct |
160 ms |
40188 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
217 ms |
40192 KB |
Output is correct |
22 |
Correct |
233 ms |
40268 KB |
Output is correct |
23 |
Correct |
219 ms |
40192 KB |
Output is correct |
24 |
Correct |
223 ms |
40200 KB |
Output is correct |
25 |
Correct |
234 ms |
40136 KB |
Output is correct |
26 |
Correct |
216 ms |
40192 KB |
Output is correct |
27 |
Correct |
214 ms |
40144 KB |
Output is correct |
28 |
Correct |
169 ms |
40264 KB |
Output is correct |
29 |
Correct |
222 ms |
40128 KB |
Output is correct |
30 |
Correct |
1 ms |
256 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 |
340 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 |
1 ms |
340 KB |
Output is correct |
40 |
Correct |
0 ms |
212 KB |
Output is correct |
41 |
Correct |
14 ms |
1620 KB |
Output is correct |
42 |
Correct |
18 ms |
1580 KB |
Output is correct |
43 |
Correct |
15 ms |
1576 KB |
Output is correct |
44 |
Correct |
14 ms |
1620 KB |
Output is correct |
45 |
Correct |
13 ms |
1620 KB |
Output is correct |
46 |
Correct |
12 ms |
1620 KB |
Output is correct |
47 |
Correct |
14 ms |
1520 KB |
Output is correct |
48 |
Correct |
12 ms |
1620 KB |
Output is correct |
49 |
Correct |
8 ms |
1620 KB |
Output is correct |
50 |
Correct |
0 ms |
212 KB |
Output is correct |
51 |
Correct |
468 ms |
40140 KB |
Output is correct |
52 |
Correct |
362 ms |
40108 KB |
Output is correct |
53 |
Correct |
401 ms |
40188 KB |
Output is correct |
54 |
Correct |
387 ms |
40200 KB |
Output is correct |
55 |
Correct |
452 ms |
40260 KB |
Output is correct |
56 |
Correct |
387 ms |
40252 KB |
Output is correct |
57 |
Correct |
428 ms |
40188 KB |
Output is correct |
58 |
Correct |
205 ms |
40196 KB |
Output is correct |
59 |
Correct |
204 ms |
40192 KB |
Output is correct |
60 |
Correct |
0 ms |
212 KB |
Output is correct |
61 |
Correct |
666 ms |
40196 KB |
Output is correct |
62 |
Correct |
640 ms |
40192 KB |
Output is correct |
63 |
Correct |
581 ms |
40188 KB |
Output is correct |
64 |
Correct |
670 ms |
40192 KB |
Output is correct |
65 |
Correct |
593 ms |
40192 KB |
Output is correct |
66 |
Correct |
646 ms |
40196 KB |
Output is correct |
67 |
Correct |
636 ms |
40132 KB |
Output is correct |
68 |
Correct |
599 ms |
40196 KB |
Output is correct |
69 |
Correct |
388 ms |
40192 KB |
Output is correct |
70 |
Correct |
1 ms |
212 KB |
Output is correct |