#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define F first
#define S second
#define pb push_back
#define lc (ind * 2)
#define rc (lc + 1)
#define md ((b + e) / 2)
const ll N = 3e5 + 5;
const ll LOG = 20;
const int MOD = 1e9 + 7;
const ll INF = 1e18 + 10;
int n, cnt[4 * N];
ll H[N], ans;
vector <int> all[N];
vector <ll> vc;
void add(int id, int b = 0, int e = n, int ind = 1){
if (b + 1 == e){
cnt[ind] ++;
return;
}
if (id < md) add(id, b, md, lc);
else add(id, md, e, rc);
cnt[ind] = cnt[lc] + cnt[rc];
return;
}
int get(int l, int r, int b = 0, int e = n, int ind = 1){
if (l <= b && e <= r){
return cnt[ind];
}
int res = 0;
if (l < md) res += get(l, r, b, md, lc);
if (md < r) res += get(l, r, md, e, rc);
return res;
}
int main() {
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cin >> n;
for (int i = 0; i < n; i++){
cin >> H[i];
vc.pb(H[i]);
}
sort(vc.begin(), vc.end());
vc.resize(unique(vc.begin(), vc.end()) - vc.begin());
for (int i = 0; i < n; i++){
int p = lower_bound(vc.begin(), vc.end(), H[i]) - vc.begin();
all[p].pb(i);
}
for (int i = 0; i < (int)vc.size(); i++){
int L, R;
for (int j : all[i]){
L = 0; R = 0;
if (j) L = get(0, j);
R = get(j, n);
ans += (L * R);
}
for (int j : all[i]){
add(j);
}
}
cout << ans << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
7404 KB |
Output is correct |
2 |
Correct |
222 ms |
31068 KB |
Output is correct |
3 |
Correct |
219 ms |
31068 KB |
Output is correct |
4 |
Correct |
223 ms |
31196 KB |
Output is correct |
5 |
Correct |
222 ms |
31068 KB |
Output is correct |
6 |
Correct |
223 ms |
31196 KB |
Output is correct |
7 |
Correct |
226 ms |
31196 KB |
Output is correct |
8 |
Correct |
219 ms |
31068 KB |
Output is correct |
9 |
Correct |
227 ms |
26820 KB |
Output is correct |
10 |
Correct |
224 ms |
26844 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
158 ms |
19420 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
158 ms |
19420 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
7404 KB |
Output is correct |
2 |
Correct |
7 ms |
7404 KB |
Output is correct |
3 |
Correct |
5 ms |
7404 KB |
Output is correct |
4 |
Correct |
6 ms |
7404 KB |
Output is correct |
5 |
Correct |
6 ms |
7404 KB |
Output is correct |
6 |
Correct |
7 ms |
7404 KB |
Output is correct |
7 |
Correct |
6 ms |
7404 KB |
Output is correct |
8 |
Correct |
5 ms |
7404 KB |
Output is correct |
9 |
Correct |
6 ms |
7404 KB |
Output is correct |
10 |
Correct |
5 ms |
7404 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
7404 KB |
Output is correct |
2 |
Correct |
7 ms |
7404 KB |
Output is correct |
3 |
Correct |
5 ms |
7404 KB |
Output is correct |
4 |
Correct |
6 ms |
7404 KB |
Output is correct |
5 |
Correct |
6 ms |
7404 KB |
Output is correct |
6 |
Correct |
7 ms |
7404 KB |
Output is correct |
7 |
Correct |
6 ms |
7404 KB |
Output is correct |
8 |
Correct |
5 ms |
7404 KB |
Output is correct |
9 |
Correct |
6 ms |
7404 KB |
Output is correct |
10 |
Correct |
5 ms |
7404 KB |
Output is correct |
11 |
Correct |
14 ms |
8172 KB |
Output is correct |
12 |
Correct |
13 ms |
8172 KB |
Output is correct |
13 |
Correct |
14 ms |
8172 KB |
Output is correct |
14 |
Correct |
14 ms |
8172 KB |
Output is correct |
15 |
Correct |
14 ms |
8172 KB |
Output is correct |
16 |
Correct |
15 ms |
8172 KB |
Output is correct |
17 |
Correct |
15 ms |
8300 KB |
Output is correct |
18 |
Correct |
14 ms |
8044 KB |
Output is correct |
19 |
Correct |
11 ms |
7788 KB |
Output is correct |
20 |
Correct |
6 ms |
7404 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
158 ms |
19420 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
7404 KB |
Output is correct |
2 |
Correct |
222 ms |
31068 KB |
Output is correct |
3 |
Correct |
219 ms |
31068 KB |
Output is correct |
4 |
Correct |
223 ms |
31196 KB |
Output is correct |
5 |
Correct |
222 ms |
31068 KB |
Output is correct |
6 |
Correct |
223 ms |
31196 KB |
Output is correct |
7 |
Correct |
226 ms |
31196 KB |
Output is correct |
8 |
Correct |
219 ms |
31068 KB |
Output is correct |
9 |
Correct |
227 ms |
26820 KB |
Output is correct |
10 |
Correct |
224 ms |
26844 KB |
Output is correct |
11 |
Incorrect |
158 ms |
19420 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |