#include <bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define rep(i,m,n) for(int i=(m); i<=(n); i++)
#define reb(i,m,n) for(int i=(m); i>=(n); i--)
#define iter(id, v) for(auto id : v)
#define fs first
#define se second
#define MP make_pair
#define pb push_back
#define bit(msk, i) ((msk >> i) & 1)
#define SZ(v) (ll)v.size()
#define ALL(v) v.begin(),v.end()
using namespace std;
mt19937_64 rd(chrono :: steady_clock :: now ().time_since_epoch().count());
ll Rand (ll l, ll r) { return uniform_int_distribution<ll> (l, r) (rd); }
const int N = 3e5 + 2;
const int Mod = 1e9 + 7;
const ll INF = 1e16;
const ll BASE = 137;
const int szBL = 350;
struct fenwick_Tree {
int m;
int fen[N];
void init (int n) {
m = n;
}
void update (int pos, int val) {
for (; pos <= m; pos += pos & -pos) fen[pos] += val;
}
int get (int pos) {
int res = 0;
for (;pos > 0; pos -= pos & -pos) res += fen[pos];
return res;
}
int get (int u, int v) {
if (u > v) return 0;
return get(v) - get(u - 1);
}
}BIT;
int n;
int a[N];
pii b[N];
void solution () {
cin >> n;
rep (i, 1, n) cin >> a[i];
BIT.init(n);
rep (i, 1, n) b[i] = MP(a[i], i);
sort (b + 1, b + 1 + n);
ll res = 0;
rep (i, 1, n) {
int L = i, R = i;
while (R < n && b[R].fs == b[R + 1].fs) ++R;
// cout << L<<","<<R<<" asd\n";
rep (j, L, R) {
int val, pos;
tie(val, pos) = b[j];
res += 1LL * BIT.get(1, pos - 1) * BIT.get(pos + 1, n);
// cout <<pos<<" "<<BIT.get(1, pos - 1)<<" "<<BIT.get(pos + 1, n)<<"\n";
}
rep (j, L, R) {
int val, pos;
tie(val, pos) = b[j];
BIT.update(pos, 1);
}
i = R;
}
cout << res <<"\n";
}
#define file(name) freopen(name".inp","r",stdin); \
freopen(name".out","w",stdout);
int main () {
// file("DTREE");
ios_base :: sync_with_stdio(false); cin.tie(0); cout.tie(0);
int num_Test = 1;
// cin >> num_Test;
while (num_Test--)
solution();
}
/*
no bug +5
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
19 ms |
3852 KB |
Output is correct |
3 |
Correct |
20 ms |
3924 KB |
Output is correct |
4 |
Correct |
19 ms |
3856 KB |
Output is correct |
5 |
Correct |
19 ms |
3932 KB |
Output is correct |
6 |
Correct |
19 ms |
3932 KB |
Output is correct |
7 |
Correct |
19 ms |
3932 KB |
Output is correct |
8 |
Correct |
19 ms |
3920 KB |
Output is correct |
9 |
Correct |
19 ms |
3852 KB |
Output is correct |
10 |
Correct |
19 ms |
3932 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
41 ms |
5716 KB |
Output is correct |
2 |
Correct |
47 ms |
5724 KB |
Output is correct |
3 |
Correct |
45 ms |
5716 KB |
Output is correct |
4 |
Correct |
46 ms |
5716 KB |
Output is correct |
5 |
Correct |
46 ms |
5596 KB |
Output is correct |
6 |
Correct |
46 ms |
5716 KB |
Output is correct |
7 |
Correct |
50 ms |
5712 KB |
Output is correct |
8 |
Correct |
33 ms |
5712 KB |
Output is correct |
9 |
Correct |
32 ms |
5712 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
41 ms |
5716 KB |
Output is correct |
2 |
Correct |
47 ms |
5724 KB |
Output is correct |
3 |
Correct |
45 ms |
5716 KB |
Output is correct |
4 |
Correct |
46 ms |
5716 KB |
Output is correct |
5 |
Correct |
46 ms |
5596 KB |
Output is correct |
6 |
Correct |
46 ms |
5716 KB |
Output is correct |
7 |
Correct |
50 ms |
5712 KB |
Output is correct |
8 |
Correct |
33 ms |
5712 KB |
Output is correct |
9 |
Correct |
32 ms |
5712 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
55 ms |
5844 KB |
Output is correct |
12 |
Correct |
53 ms |
5988 KB |
Output is correct |
13 |
Correct |
52 ms |
5980 KB |
Output is correct |
14 |
Correct |
54 ms |
5856 KB |
Output is correct |
15 |
Correct |
52 ms |
5968 KB |
Output is correct |
16 |
Correct |
50 ms |
5860 KB |
Output is correct |
17 |
Correct |
54 ms |
5972 KB |
Output is correct |
18 |
Correct |
25 ms |
5980 KB |
Output is correct |
19 |
Correct |
25 ms |
5968 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
41 ms |
5716 KB |
Output is correct |
2 |
Correct |
47 ms |
5724 KB |
Output is correct |
3 |
Correct |
45 ms |
5716 KB |
Output is correct |
4 |
Correct |
46 ms |
5716 KB |
Output is correct |
5 |
Correct |
46 ms |
5596 KB |
Output is correct |
6 |
Correct |
46 ms |
5716 KB |
Output is correct |
7 |
Correct |
50 ms |
5712 KB |
Output is correct |
8 |
Correct |
33 ms |
5712 KB |
Output is correct |
9 |
Correct |
32 ms |
5712 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
55 ms |
5844 KB |
Output is correct |
12 |
Correct |
53 ms |
5988 KB |
Output is correct |
13 |
Correct |
52 ms |
5980 KB |
Output is correct |
14 |
Correct |
54 ms |
5856 KB |
Output is correct |
15 |
Correct |
52 ms |
5968 KB |
Output is correct |
16 |
Correct |
50 ms |
5860 KB |
Output is correct |
17 |
Correct |
54 ms |
5972 KB |
Output is correct |
18 |
Correct |
25 ms |
5980 KB |
Output is correct |
19 |
Correct |
25 ms |
5968 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
56 ms |
6736 KB |
Output is correct |
22 |
Correct |
58 ms |
6740 KB |
Output is correct |
23 |
Correct |
61 ms |
6740 KB |
Output is correct |
24 |
Correct |
57 ms |
6864 KB |
Output is correct |
25 |
Correct |
55 ms |
6740 KB |
Output is correct |
26 |
Correct |
57 ms |
6736 KB |
Output is correct |
27 |
Correct |
57 ms |
6740 KB |
Output is correct |
28 |
Correct |
33 ms |
6816 KB |
Output is correct |
29 |
Correct |
34 ms |
6740 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
19 ms |
3852 KB |
Output is correct |
3 |
Correct |
20 ms |
3924 KB |
Output is correct |
4 |
Correct |
19 ms |
3856 KB |
Output is correct |
5 |
Correct |
19 ms |
3932 KB |
Output is correct |
6 |
Correct |
19 ms |
3932 KB |
Output is correct |
7 |
Correct |
19 ms |
3932 KB |
Output is correct |
8 |
Correct |
19 ms |
3920 KB |
Output is correct |
9 |
Correct |
19 ms |
3852 KB |
Output is correct |
10 |
Correct |
19 ms |
3932 KB |
Output is correct |
11 |
Correct |
41 ms |
5716 KB |
Output is correct |
12 |
Correct |
47 ms |
5724 KB |
Output is correct |
13 |
Correct |
45 ms |
5716 KB |
Output is correct |
14 |
Correct |
46 ms |
5716 KB |
Output is correct |
15 |
Correct |
46 ms |
5596 KB |
Output is correct |
16 |
Correct |
46 ms |
5716 KB |
Output is correct |
17 |
Correct |
50 ms |
5712 KB |
Output is correct |
18 |
Correct |
33 ms |
5712 KB |
Output is correct |
19 |
Correct |
32 ms |
5712 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
55 ms |
5844 KB |
Output is correct |
22 |
Correct |
53 ms |
5988 KB |
Output is correct |
23 |
Correct |
52 ms |
5980 KB |
Output is correct |
24 |
Correct |
54 ms |
5856 KB |
Output is correct |
25 |
Correct |
52 ms |
5968 KB |
Output is correct |
26 |
Correct |
50 ms |
5860 KB |
Output is correct |
27 |
Correct |
54 ms |
5972 KB |
Output is correct |
28 |
Correct |
25 ms |
5980 KB |
Output is correct |
29 |
Correct |
25 ms |
5968 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
32 |
Halted |
0 ms |
0 KB |
- |