#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();
}
};
long long izquierda[100000], derecha[100000];
pair<long long, int> arreglo[100000];
int cnt = 1;
int main(){
int n;
cin>>n;
long long H[n+1];
for(int i=1; i<=n; i++){
cin>>H[i];
}
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 |
Runtime error |
190 ms |
11464 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
50 ms |
11404 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
50 ms |
11404 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
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 |
2 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
2 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 |
2 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
2 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 |
17 ms |
1620 KB |
Output is correct |
12 |
Correct |
14 ms |
1528 KB |
Output is correct |
13 |
Correct |
14 ms |
1532 KB |
Output is correct |
14 |
Correct |
15 ms |
1600 KB |
Output is correct |
15 |
Correct |
13 ms |
1604 KB |
Output is correct |
16 |
Correct |
14 ms |
1620 KB |
Output is correct |
17 |
Correct |
12 ms |
1620 KB |
Output is correct |
18 |
Correct |
12 ms |
1532 KB |
Output is correct |
19 |
Correct |
7 ms |
1620 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
50 ms |
11404 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Runtime error |
190 ms |
11464 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |