// author : anhtun_hi , nqg
#include <bits/stdc++.h>
#define ll long long
#define ii pair<ll, ll>
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define reset(h, v) memset(h, v, sizeof h)
#define Forv(i, a) for(auto& i : a)
#define For(i, a, b) for(int i = a; i <= b; ++i)
#define Ford(i, a, b) for(int i = a; i >= b; --i)
#define c_bit(i) __builtin_popcountll(i)
#define Bit(mask, i) ((mask >> i) & 1LL)
#define onbit(mask, i) ((mask) bitor (1LL << i))
#define offbit(mask, i) ((mask) &~ (1LL << i))
#define TIME (1.0 * clock() / CLOCKS_PER_SEC)
using namespace std;
namespace std {
template <typename T, int D>
struct _vector : public vector <_vector <T, D - 1>> {
static_assert(D >= 1, "Dimension must be positive!");
template <typename... Args>
_vector(int n = 0, Args... args) : vector <_vector <T, D - 1>> (n, _vector <T, D - 1> (args...)) {}
};
template <typename T> struct _vector <T, 1> : public vector <T> {
_vector(int n = 0, const T& val = T()) : vector <T> (n, val) {}
};
template <class A, class B> bool minimize(A &a, B b){return a > b ? a = b, true : false;}
template <class A, class B> bool maximize(A &a, B b){return a < b ? a = b, true : false;}
}
const int dx[] = {0, 0, +1, -1}, dy[] = {-1, +1, 0, 0}, LOG = 20, base = 311, inf = 1e9 + 5;
const int MAXN = 1e6 + 5;
const ll mod = 998244353;
const ll oo = 1e18;
//#define int long long
int n; ll h[MAXN], suff[MAXN], pref[MAXN], bit[MAXN];
void update(int u, int val){
while(u <= 1e6) bit[u] += val, u += u &- u;
}
int get(int u){
int res = 0;
while(u) res += bit[u], u -= u &- u;
return res;
}
void Solve() {
cin >> n;
_vector<ll, 1> compress;
For(i, 1, n) cin >> h[i], compress.push_back(h[i]);
sort(all(compress)), compress.resize(unique(all(compress)) - compress.begin());
For(i, 1, n) h[i] = lower_bound(all(compress), h[i]) - compress.begin() + 1;
reset(bit, 0);
For(i, 1, n) {
pref[i] = get(h[i] - 1);
update(h[i], 1);
}
reset(bit, 0);
Ford(i, n, 1) {
suff[i] = get(h[i] - 1);
update(h[i], 1);
}
ll ans = 0;
For(i, 1, n) ans += pref[i] * suff[i];
cout << ans << '\n';
}
signed main() {
cin.tie(0) -> sync_with_stdio(0);
// if(fopen("a.inp", "r")) {
// freopen("a.inp", "r", stdin);
// freopen("a.out", "w", stdout);
// }
int t = 1;
// cin >> t;
while(t --) Solve();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
12880 KB |
Output is correct |
2 |
Correct |
87 ms |
28704 KB |
Output is correct |
3 |
Correct |
101 ms |
28712 KB |
Output is correct |
4 |
Correct |
86 ms |
28628 KB |
Output is correct |
5 |
Correct |
82 ms |
28856 KB |
Output is correct |
6 |
Correct |
87 ms |
28996 KB |
Output is correct |
7 |
Correct |
100 ms |
28856 KB |
Output is correct |
8 |
Correct |
85 ms |
28856 KB |
Output is correct |
9 |
Correct |
86 ms |
28864 KB |
Output is correct |
10 |
Correct |
88 ms |
29028 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
67 ms |
23736 KB |
Output is correct |
2 |
Correct |
68 ms |
23736 KB |
Output is correct |
3 |
Correct |
64 ms |
23736 KB |
Output is correct |
4 |
Correct |
65 ms |
23736 KB |
Output is correct |
5 |
Correct |
67 ms |
23736 KB |
Output is correct |
6 |
Correct |
69 ms |
23884 KB |
Output is correct |
7 |
Correct |
64 ms |
23732 KB |
Output is correct |
8 |
Correct |
63 ms |
23740 KB |
Output is correct |
9 |
Correct |
66 ms |
23736 KB |
Output is correct |
10 |
Correct |
3 ms |
12880 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
67 ms |
23736 KB |
Output is correct |
2 |
Correct |
68 ms |
23736 KB |
Output is correct |
3 |
Correct |
64 ms |
23736 KB |
Output is correct |
4 |
Correct |
65 ms |
23736 KB |
Output is correct |
5 |
Correct |
67 ms |
23736 KB |
Output is correct |
6 |
Correct |
69 ms |
23884 KB |
Output is correct |
7 |
Correct |
64 ms |
23732 KB |
Output is correct |
8 |
Correct |
63 ms |
23740 KB |
Output is correct |
9 |
Correct |
66 ms |
23736 KB |
Output is correct |
10 |
Correct |
3 ms |
12880 KB |
Output is correct |
11 |
Correct |
80 ms |
23988 KB |
Output is correct |
12 |
Correct |
79 ms |
24004 KB |
Output is correct |
13 |
Correct |
76 ms |
24248 KB |
Output is correct |
14 |
Correct |
75 ms |
23988 KB |
Output is correct |
15 |
Correct |
75 ms |
24116 KB |
Output is correct |
16 |
Correct |
76 ms |
24004 KB |
Output is correct |
17 |
Correct |
76 ms |
23988 KB |
Output is correct |
18 |
Correct |
60 ms |
23988 KB |
Output is correct |
19 |
Correct |
65 ms |
24112 KB |
Output is correct |
20 |
Correct |
3 ms |
12880 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
12880 KB |
Output is correct |
2 |
Correct |
3 ms |
12880 KB |
Output is correct |
3 |
Correct |
3 ms |
12880 KB |
Output is correct |
4 |
Correct |
3 ms |
12928 KB |
Output is correct |
5 |
Correct |
4 ms |
12880 KB |
Output is correct |
6 |
Correct |
3 ms |
12880 KB |
Output is correct |
7 |
Correct |
3 ms |
12880 KB |
Output is correct |
8 |
Correct |
3 ms |
12880 KB |
Output is correct |
9 |
Correct |
3 ms |
12880 KB |
Output is correct |
10 |
Correct |
3 ms |
13048 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
12880 KB |
Output is correct |
2 |
Correct |
3 ms |
12880 KB |
Output is correct |
3 |
Correct |
3 ms |
12880 KB |
Output is correct |
4 |
Correct |
3 ms |
12928 KB |
Output is correct |
5 |
Correct |
4 ms |
12880 KB |
Output is correct |
6 |
Correct |
3 ms |
12880 KB |
Output is correct |
7 |
Correct |
3 ms |
12880 KB |
Output is correct |
8 |
Correct |
3 ms |
12880 KB |
Output is correct |
9 |
Correct |
3 ms |
12880 KB |
Output is correct |
10 |
Correct |
3 ms |
13048 KB |
Output is correct |
11 |
Correct |
6 ms |
13136 KB |
Output is correct |
12 |
Correct |
6 ms |
13136 KB |
Output is correct |
13 |
Correct |
7 ms |
13136 KB |
Output is correct |
14 |
Correct |
6 ms |
13136 KB |
Output is correct |
15 |
Correct |
6 ms |
13300 KB |
Output is correct |
16 |
Correct |
6 ms |
13280 KB |
Output is correct |
17 |
Correct |
6 ms |
13136 KB |
Output is correct |
18 |
Correct |
6 ms |
13136 KB |
Output is correct |
19 |
Correct |
5 ms |
13204 KB |
Output is correct |
20 |
Correct |
3 ms |
12880 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
67 ms |
23736 KB |
Output is correct |
2 |
Correct |
68 ms |
23736 KB |
Output is correct |
3 |
Correct |
64 ms |
23736 KB |
Output is correct |
4 |
Correct |
65 ms |
23736 KB |
Output is correct |
5 |
Correct |
67 ms |
23736 KB |
Output is correct |
6 |
Correct |
69 ms |
23884 KB |
Output is correct |
7 |
Correct |
64 ms |
23732 KB |
Output is correct |
8 |
Correct |
63 ms |
23740 KB |
Output is correct |
9 |
Correct |
66 ms |
23736 KB |
Output is correct |
10 |
Correct |
3 ms |
12880 KB |
Output is correct |
11 |
Correct |
80 ms |
23988 KB |
Output is correct |
12 |
Correct |
79 ms |
24004 KB |
Output is correct |
13 |
Correct |
76 ms |
24248 KB |
Output is correct |
14 |
Correct |
75 ms |
23988 KB |
Output is correct |
15 |
Correct |
75 ms |
24116 KB |
Output is correct |
16 |
Correct |
76 ms |
24004 KB |
Output is correct |
17 |
Correct |
76 ms |
23988 KB |
Output is correct |
18 |
Correct |
60 ms |
23988 KB |
Output is correct |
19 |
Correct |
65 ms |
24112 KB |
Output is correct |
20 |
Correct |
3 ms |
12880 KB |
Output is correct |
21 |
Correct |
120 ms |
25016 KB |
Output is correct |
22 |
Correct |
117 ms |
24868 KB |
Output is correct |
23 |
Correct |
116 ms |
24872 KB |
Output is correct |
24 |
Correct |
116 ms |
25016 KB |
Output is correct |
25 |
Correct |
118 ms |
24916 KB |
Output is correct |
26 |
Correct |
122 ms |
25016 KB |
Output is correct |
27 |
Correct |
124 ms |
25016 KB |
Output is correct |
28 |
Correct |
60 ms |
25016 KB |
Output is correct |
29 |
Correct |
60 ms |
25028 KB |
Output is correct |
30 |
Correct |
3 ms |
13048 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
12880 KB |
Output is correct |
2 |
Correct |
87 ms |
28704 KB |
Output is correct |
3 |
Correct |
101 ms |
28712 KB |
Output is correct |
4 |
Correct |
86 ms |
28628 KB |
Output is correct |
5 |
Correct |
82 ms |
28856 KB |
Output is correct |
6 |
Correct |
87 ms |
28996 KB |
Output is correct |
7 |
Correct |
100 ms |
28856 KB |
Output is correct |
8 |
Correct |
85 ms |
28856 KB |
Output is correct |
9 |
Correct |
86 ms |
28864 KB |
Output is correct |
10 |
Correct |
88 ms |
29028 KB |
Output is correct |
11 |
Correct |
67 ms |
23736 KB |
Output is correct |
12 |
Correct |
68 ms |
23736 KB |
Output is correct |
13 |
Correct |
64 ms |
23736 KB |
Output is correct |
14 |
Correct |
65 ms |
23736 KB |
Output is correct |
15 |
Correct |
67 ms |
23736 KB |
Output is correct |
16 |
Correct |
69 ms |
23884 KB |
Output is correct |
17 |
Correct |
64 ms |
23732 KB |
Output is correct |
18 |
Correct |
63 ms |
23740 KB |
Output is correct |
19 |
Correct |
66 ms |
23736 KB |
Output is correct |
20 |
Correct |
3 ms |
12880 KB |
Output is correct |
21 |
Correct |
80 ms |
23988 KB |
Output is correct |
22 |
Correct |
79 ms |
24004 KB |
Output is correct |
23 |
Correct |
76 ms |
24248 KB |
Output is correct |
24 |
Correct |
75 ms |
23988 KB |
Output is correct |
25 |
Correct |
75 ms |
24116 KB |
Output is correct |
26 |
Correct |
76 ms |
24004 KB |
Output is correct |
27 |
Correct |
76 ms |
23988 KB |
Output is correct |
28 |
Correct |
60 ms |
23988 KB |
Output is correct |
29 |
Correct |
65 ms |
24112 KB |
Output is correct |
30 |
Correct |
3 ms |
12880 KB |
Output is correct |
31 |
Correct |
3 ms |
12880 KB |
Output is correct |
32 |
Correct |
3 ms |
12880 KB |
Output is correct |
33 |
Correct |
3 ms |
12880 KB |
Output is correct |
34 |
Correct |
3 ms |
12928 KB |
Output is correct |
35 |
Correct |
4 ms |
12880 KB |
Output is correct |
36 |
Correct |
3 ms |
12880 KB |
Output is correct |
37 |
Correct |
3 ms |
12880 KB |
Output is correct |
38 |
Correct |
3 ms |
12880 KB |
Output is correct |
39 |
Correct |
3 ms |
12880 KB |
Output is correct |
40 |
Correct |
3 ms |
13048 KB |
Output is correct |
41 |
Correct |
6 ms |
13136 KB |
Output is correct |
42 |
Correct |
6 ms |
13136 KB |
Output is correct |
43 |
Correct |
7 ms |
13136 KB |
Output is correct |
44 |
Correct |
6 ms |
13136 KB |
Output is correct |
45 |
Correct |
6 ms |
13300 KB |
Output is correct |
46 |
Correct |
6 ms |
13280 KB |
Output is correct |
47 |
Correct |
6 ms |
13136 KB |
Output is correct |
48 |
Correct |
6 ms |
13136 KB |
Output is correct |
49 |
Correct |
5 ms |
13204 KB |
Output is correct |
50 |
Correct |
3 ms |
12880 KB |
Output is correct |
51 |
Correct |
120 ms |
25016 KB |
Output is correct |
52 |
Correct |
117 ms |
24868 KB |
Output is correct |
53 |
Correct |
116 ms |
24872 KB |
Output is correct |
54 |
Correct |
116 ms |
25016 KB |
Output is correct |
55 |
Correct |
118 ms |
24916 KB |
Output is correct |
56 |
Correct |
122 ms |
25016 KB |
Output is correct |
57 |
Correct |
124 ms |
25016 KB |
Output is correct |
58 |
Correct |
60 ms |
25016 KB |
Output is correct |
59 |
Correct |
60 ms |
25028 KB |
Output is correct |
60 |
Correct |
3 ms |
13048 KB |
Output is correct |
61 |
Correct |
154 ms |
28780 KB |
Output is correct |
62 |
Correct |
169 ms |
28712 KB |
Output is correct |
63 |
Correct |
168 ms |
28852 KB |
Output is correct |
64 |
Correct |
179 ms |
28856 KB |
Output is correct |
65 |
Correct |
163 ms |
28856 KB |
Output is correct |
66 |
Correct |
165 ms |
28856 KB |
Output is correct |
67 |
Correct |
162 ms |
28856 KB |
Output is correct |
68 |
Correct |
164 ms |
28856 KB |
Output is correct |
69 |
Correct |
128 ms |
25016 KB |
Output is correct |
70 |
Correct |
3 ms |
12880 KB |
Output is correct |