#include<bits/stdc++.h>
#define ll long long
#define endl '\n'
using namespace std;
const ll MAX_N = 3e5+2;
ll a[MAX_N];
ll res;
set<ll> s;
unordered_map<ll,ll> m;
ll br=1;
vector<ll> tree1(MAX_N*2);
vector<ll> tree2(MAX_N*2);
void update(vector<ll> &tree,ll node,ll tl,ll tr,ll l,ll r)
{
if(tl > r || tr < l)return;
if(tl == tr)
{
tree[node]++;
return;
}
ll mid = (tl+tr)/2;
update(tree,node*2,tl,mid,l,r);
update(tree,node*2+1,mid+1,tr,l,r);
tree[node] = tree[node*2]+tree[node*2+1];
}
ll query(vector<ll> &tree,ll node,ll tl,ll tr,ll l,ll r)
{
if(tl > r || tr < l)return 0;
if(tl >= l && tr <= r)
{
return tree[node];
}
ll mid = (tl+tr)/2;
return query(tree,node*2,tl,mid,l,r)+query(tree,node*2+1,mid+1,tr,l,r);
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
ll n;
cin>>n;
vector<ll> l(n);
vector<ll> r(n);
for(ll i=0; i<n; i++)
{
cin>>a[i];
s.insert(a[i]);
}
for(auto &it : s)
{
m[it] = br;
br++;
}
br--;
update(tree1,1,1,br,m[a[0]],m[a[0]]);
for(ll i=1; i<n; i++)
{
l[i] = query(tree1,1,1,br,1,m[a[i]]-1);
update(tree1,1,1,br,m[a[i]],m[a[i]]);
}
update(tree2,1,1,br,m[a[n-1]],m[a[n-1]]);
for(ll i=n-2; i>=0; i--)
{
r[i] = query(tree2,1,1,br,1,m[a[i]]-1);
update(tree2,1,1,br,m[a[i]],m[a[i]]);
}
for(ll i=0;i<n;i++)
{
res+=(l[i]*r[i]);
}
cout<<res<<endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
9728 KB |
Output is correct |
2 |
Runtime error |
281 ms |
93932 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
61 ms |
16824 KB |
Output is correct |
2 |
Correct |
51 ms |
17408 KB |
Output is correct |
3 |
Correct |
54 ms |
17408 KB |
Output is correct |
4 |
Correct |
57 ms |
17408 KB |
Output is correct |
5 |
Correct |
55 ms |
17528 KB |
Output is correct |
6 |
Correct |
52 ms |
17280 KB |
Output is correct |
7 |
Correct |
53 ms |
17408 KB |
Output is correct |
8 |
Correct |
48 ms |
17408 KB |
Output is correct |
9 |
Correct |
54 ms |
17408 KB |
Output is correct |
10 |
Correct |
9 ms |
9728 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
61 ms |
16824 KB |
Output is correct |
2 |
Correct |
51 ms |
17408 KB |
Output is correct |
3 |
Correct |
54 ms |
17408 KB |
Output is correct |
4 |
Correct |
57 ms |
17408 KB |
Output is correct |
5 |
Correct |
55 ms |
17528 KB |
Output is correct |
6 |
Correct |
52 ms |
17280 KB |
Output is correct |
7 |
Correct |
53 ms |
17408 KB |
Output is correct |
8 |
Correct |
48 ms |
17408 KB |
Output is correct |
9 |
Correct |
54 ms |
17408 KB |
Output is correct |
10 |
Correct |
9 ms |
9728 KB |
Output is correct |
11 |
Correct |
148 ms |
17656 KB |
Output is correct |
12 |
Correct |
152 ms |
17784 KB |
Output is correct |
13 |
Correct |
145 ms |
17656 KB |
Output is correct |
14 |
Correct |
147 ms |
17656 KB |
Output is correct |
15 |
Correct |
150 ms |
17656 KB |
Output is correct |
16 |
Correct |
151 ms |
17784 KB |
Output is correct |
17 |
Correct |
144 ms |
17656 KB |
Output is correct |
18 |
Correct |
102 ms |
17664 KB |
Output is correct |
19 |
Correct |
105 ms |
17664 KB |
Output is correct |
20 |
Correct |
11 ms |
9728 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
9856 KB |
Output is correct |
2 |
Correct |
10 ms |
9856 KB |
Output is correct |
3 |
Correct |
9 ms |
9856 KB |
Output is correct |
4 |
Correct |
10 ms |
9856 KB |
Output is correct |
5 |
Correct |
10 ms |
9856 KB |
Output is correct |
6 |
Correct |
10 ms |
9856 KB |
Output is correct |
7 |
Correct |
11 ms |
9856 KB |
Output is correct |
8 |
Correct |
9 ms |
9856 KB |
Output is correct |
9 |
Correct |
10 ms |
9728 KB |
Output is correct |
10 |
Correct |
9 ms |
9728 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
9856 KB |
Output is correct |
2 |
Correct |
10 ms |
9856 KB |
Output is correct |
3 |
Correct |
9 ms |
9856 KB |
Output is correct |
4 |
Correct |
10 ms |
9856 KB |
Output is correct |
5 |
Correct |
10 ms |
9856 KB |
Output is correct |
6 |
Correct |
10 ms |
9856 KB |
Output is correct |
7 |
Correct |
11 ms |
9856 KB |
Output is correct |
8 |
Correct |
9 ms |
9856 KB |
Output is correct |
9 |
Correct |
10 ms |
9728 KB |
Output is correct |
10 |
Correct |
9 ms |
9728 KB |
Output is correct |
11 |
Correct |
26 ms |
11136 KB |
Output is correct |
12 |
Correct |
24 ms |
11136 KB |
Output is correct |
13 |
Correct |
26 ms |
11136 KB |
Output is correct |
14 |
Correct |
24 ms |
11136 KB |
Output is correct |
15 |
Correct |
24 ms |
11008 KB |
Output is correct |
16 |
Correct |
24 ms |
11136 KB |
Output is correct |
17 |
Correct |
24 ms |
11008 KB |
Output is correct |
18 |
Correct |
22 ms |
10496 KB |
Output is correct |
19 |
Correct |
15 ms |
10112 KB |
Output is correct |
20 |
Correct |
9 ms |
9728 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
61 ms |
16824 KB |
Output is correct |
2 |
Correct |
51 ms |
17408 KB |
Output is correct |
3 |
Correct |
54 ms |
17408 KB |
Output is correct |
4 |
Correct |
57 ms |
17408 KB |
Output is correct |
5 |
Correct |
55 ms |
17528 KB |
Output is correct |
6 |
Correct |
52 ms |
17280 KB |
Output is correct |
7 |
Correct |
53 ms |
17408 KB |
Output is correct |
8 |
Correct |
48 ms |
17408 KB |
Output is correct |
9 |
Correct |
54 ms |
17408 KB |
Output is correct |
10 |
Correct |
9 ms |
9728 KB |
Output is correct |
11 |
Correct |
148 ms |
17656 KB |
Output is correct |
12 |
Correct |
152 ms |
17784 KB |
Output is correct |
13 |
Correct |
145 ms |
17656 KB |
Output is correct |
14 |
Correct |
147 ms |
17656 KB |
Output is correct |
15 |
Correct |
150 ms |
17656 KB |
Output is correct |
16 |
Correct |
151 ms |
17784 KB |
Output is correct |
17 |
Correct |
144 ms |
17656 KB |
Output is correct |
18 |
Correct |
102 ms |
17664 KB |
Output is correct |
19 |
Correct |
105 ms |
17664 KB |
Output is correct |
20 |
Correct |
11 ms |
9728 KB |
Output is correct |
21 |
Correct |
457 ms |
26760 KB |
Output is correct |
22 |
Correct |
468 ms |
26888 KB |
Output is correct |
23 |
Correct |
614 ms |
26888 KB |
Output is correct |
24 |
Correct |
464 ms |
27016 KB |
Output is correct |
25 |
Correct |
485 ms |
26924 KB |
Output is correct |
26 |
Correct |
470 ms |
26760 KB |
Output is correct |
27 |
Correct |
488 ms |
26768 KB |
Output is correct |
28 |
Correct |
285 ms |
26760 KB |
Output is correct |
29 |
Correct |
301 ms |
26760 KB |
Output is correct |
30 |
Correct |
11 ms |
9728 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
9728 KB |
Output is correct |
2 |
Runtime error |
281 ms |
93932 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
3 |
Halted |
0 ms |
0 KB |
- |