#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#define ll long long
#define pll pair<ll, ll>
#define pii pair<int, int>
#define pff pair<float, float>
#define coutpair(p) cout << p.first << " " << p.second << "\n"
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_multiset;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n; cin >> n;
ll h[n];
for (int i=0; i<n; i++) cin >> h[i];
ordered_set lcnt, rcnt; //to check for bottom values
ll left[n], right[n]; //for a fixed point i, how many numbers are
//smaller than it on each side
left[0] = 0, right[n-1] = 0;
ll ans = 0;
lcnt.insert(h[0]);
for (int i=1; i<n; i++){
left[i] = lcnt.order_of_key(h[i]);
lcnt.insert(h[i]);
}
rcnt.insert(h[n-1]);
for (int i=n-2; i>=0; i--){
right[i] = rcnt.order_of_key(h[i]);
ans += left[i]*right[i];
rcnt.insert(h[i]);
}
cout << ans;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
563 ms |
50460 KB |
Output is correct |
3 |
Correct |
587 ms |
50596 KB |
Output is correct |
4 |
Correct |
647 ms |
50648 KB |
Output is correct |
5 |
Correct |
644 ms |
50552 KB |
Output is correct |
6 |
Correct |
661 ms |
50596 KB |
Output is correct |
7 |
Correct |
639 ms |
50548 KB |
Output is correct |
8 |
Correct |
596 ms |
50452 KB |
Output is correct |
9 |
Correct |
369 ms |
32388 KB |
Output is correct |
10 |
Correct |
339 ms |
32788 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
22 ms |
8028 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
22 ms |
8028 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
22 ms |
8028 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
563 ms |
50460 KB |
Output is correct |
3 |
Correct |
587 ms |
50596 KB |
Output is correct |
4 |
Correct |
647 ms |
50648 KB |
Output is correct |
5 |
Correct |
644 ms |
50552 KB |
Output is correct |
6 |
Correct |
661 ms |
50596 KB |
Output is correct |
7 |
Correct |
639 ms |
50548 KB |
Output is correct |
8 |
Correct |
596 ms |
50452 KB |
Output is correct |
9 |
Correct |
369 ms |
32388 KB |
Output is correct |
10 |
Correct |
339 ms |
32788 KB |
Output is correct |
11 |
Incorrect |
22 ms |
8028 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |