#include<bits/stdc++.h>
#define ll long long
#define f first
#define s second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define ull unsigned ll
#define pb push_back
#define mp make_pair
using namespace std;
int n;
ll a[300001];
vector<ll>t[2000001];
void build(int v,int l,int r){
if(l==r){
t[v].pb(a[l]);
return;
}
int m=(l+r)/2;
build(2*v,l,m);
build(2*v+1,m+1,r);
t[v].resize((int)t[2*v].size()+(int)t[2*v+1].size());
merge(t[2*v].begin(),t[2*v].end(),t[2*v+1].begin(),t[2*v+1].end(),t[v].begin());
}
ll get(int v,int l,int r,int tl,int tr,ll val){
if(l==tl&&r==tr){
ll k=lower_bound(t[v].begin(),t[v].end(),val)-t[v].begin();
return k;
}
int tm=(tl+tr)/2;
if(r<=tm)return get(2*v,l,r,tl,tm,val);
if(l>tm)return get(2*v+1,l,r,tm+1,tr,val);
return get(2*v,l,tm,tl,tm,val)+get(2*v+1,tm+1,r,tm+1,tr,val);
}
ll ans=0;
int main(){
cin>>n;
for(int i=1;i<=n;i++)cin>>a[i];
build(1,1,n);
for(int i=2;i<n;i++){
ans+=get(1,1,i-1,1,n,a[i])*get(1,i+1,n,1,n,a[i]);
}
cout<<ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
34 ms |
47232 KB |
Output is correct |
2 |
Correct |
757 ms |
111352 KB |
Output is correct |
3 |
Correct |
745 ms |
109020 KB |
Output is correct |
4 |
Correct |
744 ms |
109052 KB |
Output is correct |
5 |
Correct |
754 ms |
109048 KB |
Output is correct |
6 |
Correct |
750 ms |
109048 KB |
Output is correct |
7 |
Correct |
746 ms |
109176 KB |
Output is correct |
8 |
Correct |
748 ms |
109048 KB |
Output is correct |
9 |
Correct |
772 ms |
109048 KB |
Output is correct |
10 |
Correct |
762 ms |
109176 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
427 ms |
105720 KB |
Output is correct |
2 |
Correct |
439 ms |
105720 KB |
Output is correct |
3 |
Correct |
437 ms |
105848 KB |
Output is correct |
4 |
Correct |
432 ms |
105848 KB |
Output is correct |
5 |
Correct |
431 ms |
105848 KB |
Output is correct |
6 |
Correct |
441 ms |
105724 KB |
Output is correct |
7 |
Correct |
436 ms |
105768 KB |
Output is correct |
8 |
Correct |
429 ms |
105720 KB |
Output is correct |
9 |
Correct |
417 ms |
105720 KB |
Output is correct |
10 |
Correct |
31 ms |
47224 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
427 ms |
105720 KB |
Output is correct |
2 |
Correct |
439 ms |
105720 KB |
Output is correct |
3 |
Correct |
437 ms |
105848 KB |
Output is correct |
4 |
Correct |
432 ms |
105848 KB |
Output is correct |
5 |
Correct |
431 ms |
105848 KB |
Output is correct |
6 |
Correct |
441 ms |
105724 KB |
Output is correct |
7 |
Correct |
436 ms |
105768 KB |
Output is correct |
8 |
Correct |
429 ms |
105720 KB |
Output is correct |
9 |
Correct |
417 ms |
105720 KB |
Output is correct |
10 |
Correct |
31 ms |
47224 KB |
Output is correct |
11 |
Correct |
706 ms |
105776 KB |
Output is correct |
12 |
Correct |
710 ms |
105848 KB |
Output is correct |
13 |
Correct |
706 ms |
105976 KB |
Output is correct |
14 |
Correct |
711 ms |
106008 KB |
Output is correct |
15 |
Correct |
711 ms |
105848 KB |
Output is correct |
16 |
Correct |
723 ms |
105976 KB |
Output is correct |
17 |
Correct |
709 ms |
105848 KB |
Output is correct |
18 |
Correct |
430 ms |
105924 KB |
Output is correct |
19 |
Correct |
419 ms |
105720 KB |
Output is correct |
20 |
Correct |
32 ms |
47224 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
34 ms |
47488 KB |
Output is correct |
2 |
Correct |
33 ms |
47352 KB |
Output is correct |
3 |
Correct |
33 ms |
47352 KB |
Output is correct |
4 |
Correct |
33 ms |
47360 KB |
Output is correct |
5 |
Correct |
33 ms |
47424 KB |
Output is correct |
6 |
Correct |
33 ms |
47352 KB |
Output is correct |
7 |
Correct |
35 ms |
47360 KB |
Output is correct |
8 |
Correct |
35 ms |
47360 KB |
Output is correct |
9 |
Correct |
33 ms |
47352 KB |
Output is correct |
10 |
Correct |
32 ms |
47224 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
34 ms |
47488 KB |
Output is correct |
2 |
Correct |
33 ms |
47352 KB |
Output is correct |
3 |
Correct |
33 ms |
47352 KB |
Output is correct |
4 |
Correct |
33 ms |
47360 KB |
Output is correct |
5 |
Correct |
33 ms |
47424 KB |
Output is correct |
6 |
Correct |
33 ms |
47352 KB |
Output is correct |
7 |
Correct |
35 ms |
47360 KB |
Output is correct |
8 |
Correct |
35 ms |
47360 KB |
Output is correct |
9 |
Correct |
33 ms |
47352 KB |
Output is correct |
10 |
Correct |
32 ms |
47224 KB |
Output is correct |
11 |
Correct |
61 ms |
49016 KB |
Output is correct |
12 |
Correct |
58 ms |
49016 KB |
Output is correct |
13 |
Correct |
58 ms |
49016 KB |
Output is correct |
14 |
Correct |
60 ms |
49016 KB |
Output is correct |
15 |
Correct |
59 ms |
49092 KB |
Output is correct |
16 |
Correct |
59 ms |
49016 KB |
Output is correct |
17 |
Correct |
59 ms |
49016 KB |
Output is correct |
18 |
Correct |
59 ms |
49144 KB |
Output is correct |
19 |
Correct |
48 ms |
48888 KB |
Output is correct |
20 |
Correct |
33 ms |
47232 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
427 ms |
105720 KB |
Output is correct |
2 |
Correct |
439 ms |
105720 KB |
Output is correct |
3 |
Correct |
437 ms |
105848 KB |
Output is correct |
4 |
Correct |
432 ms |
105848 KB |
Output is correct |
5 |
Correct |
431 ms |
105848 KB |
Output is correct |
6 |
Correct |
441 ms |
105724 KB |
Output is correct |
7 |
Correct |
436 ms |
105768 KB |
Output is correct |
8 |
Correct |
429 ms |
105720 KB |
Output is correct |
9 |
Correct |
417 ms |
105720 KB |
Output is correct |
10 |
Correct |
31 ms |
47224 KB |
Output is correct |
11 |
Correct |
706 ms |
105776 KB |
Output is correct |
12 |
Correct |
710 ms |
105848 KB |
Output is correct |
13 |
Correct |
706 ms |
105976 KB |
Output is correct |
14 |
Correct |
711 ms |
106008 KB |
Output is correct |
15 |
Correct |
711 ms |
105848 KB |
Output is correct |
16 |
Correct |
723 ms |
105976 KB |
Output is correct |
17 |
Correct |
709 ms |
105848 KB |
Output is correct |
18 |
Correct |
430 ms |
105924 KB |
Output is correct |
19 |
Correct |
419 ms |
105720 KB |
Output is correct |
20 |
Correct |
32 ms |
47224 KB |
Output is correct |
21 |
Correct |
856 ms |
105924 KB |
Output is correct |
22 |
Correct |
907 ms |
105940 KB |
Output is correct |
23 |
Correct |
875 ms |
105720 KB |
Output is correct |
24 |
Correct |
877 ms |
105784 KB |
Output is correct |
25 |
Correct |
855 ms |
105848 KB |
Output is correct |
26 |
Correct |
870 ms |
105848 KB |
Output is correct |
27 |
Correct |
904 ms |
105840 KB |
Output is correct |
28 |
Correct |
483 ms |
105976 KB |
Output is correct |
29 |
Correct |
486 ms |
105776 KB |
Output is correct |
30 |
Correct |
34 ms |
47352 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
34 ms |
47232 KB |
Output is correct |
2 |
Correct |
757 ms |
111352 KB |
Output is correct |
3 |
Correct |
745 ms |
109020 KB |
Output is correct |
4 |
Correct |
744 ms |
109052 KB |
Output is correct |
5 |
Correct |
754 ms |
109048 KB |
Output is correct |
6 |
Correct |
750 ms |
109048 KB |
Output is correct |
7 |
Correct |
746 ms |
109176 KB |
Output is correct |
8 |
Correct |
748 ms |
109048 KB |
Output is correct |
9 |
Correct |
772 ms |
109048 KB |
Output is correct |
10 |
Correct |
762 ms |
109176 KB |
Output is correct |
11 |
Correct |
427 ms |
105720 KB |
Output is correct |
12 |
Correct |
439 ms |
105720 KB |
Output is correct |
13 |
Correct |
437 ms |
105848 KB |
Output is correct |
14 |
Correct |
432 ms |
105848 KB |
Output is correct |
15 |
Correct |
431 ms |
105848 KB |
Output is correct |
16 |
Correct |
441 ms |
105724 KB |
Output is correct |
17 |
Correct |
436 ms |
105768 KB |
Output is correct |
18 |
Correct |
429 ms |
105720 KB |
Output is correct |
19 |
Correct |
417 ms |
105720 KB |
Output is correct |
20 |
Correct |
31 ms |
47224 KB |
Output is correct |
21 |
Correct |
706 ms |
105776 KB |
Output is correct |
22 |
Correct |
710 ms |
105848 KB |
Output is correct |
23 |
Correct |
706 ms |
105976 KB |
Output is correct |
24 |
Correct |
711 ms |
106008 KB |
Output is correct |
25 |
Correct |
711 ms |
105848 KB |
Output is correct |
26 |
Correct |
723 ms |
105976 KB |
Output is correct |
27 |
Correct |
709 ms |
105848 KB |
Output is correct |
28 |
Correct |
430 ms |
105924 KB |
Output is correct |
29 |
Correct |
419 ms |
105720 KB |
Output is correct |
30 |
Correct |
32 ms |
47224 KB |
Output is correct |
31 |
Correct |
34 ms |
47488 KB |
Output is correct |
32 |
Correct |
33 ms |
47352 KB |
Output is correct |
33 |
Correct |
33 ms |
47352 KB |
Output is correct |
34 |
Correct |
33 ms |
47360 KB |
Output is correct |
35 |
Correct |
33 ms |
47424 KB |
Output is correct |
36 |
Correct |
33 ms |
47352 KB |
Output is correct |
37 |
Correct |
35 ms |
47360 KB |
Output is correct |
38 |
Correct |
35 ms |
47360 KB |
Output is correct |
39 |
Correct |
33 ms |
47352 KB |
Output is correct |
40 |
Correct |
32 ms |
47224 KB |
Output is correct |
41 |
Correct |
61 ms |
49016 KB |
Output is correct |
42 |
Correct |
58 ms |
49016 KB |
Output is correct |
43 |
Correct |
58 ms |
49016 KB |
Output is correct |
44 |
Correct |
60 ms |
49016 KB |
Output is correct |
45 |
Correct |
59 ms |
49092 KB |
Output is correct |
46 |
Correct |
59 ms |
49016 KB |
Output is correct |
47 |
Correct |
59 ms |
49016 KB |
Output is correct |
48 |
Correct |
59 ms |
49144 KB |
Output is correct |
49 |
Correct |
48 ms |
48888 KB |
Output is correct |
50 |
Correct |
33 ms |
47232 KB |
Output is correct |
51 |
Correct |
856 ms |
105924 KB |
Output is correct |
52 |
Correct |
907 ms |
105940 KB |
Output is correct |
53 |
Correct |
875 ms |
105720 KB |
Output is correct |
54 |
Correct |
877 ms |
105784 KB |
Output is correct |
55 |
Correct |
855 ms |
105848 KB |
Output is correct |
56 |
Correct |
870 ms |
105848 KB |
Output is correct |
57 |
Correct |
904 ms |
105840 KB |
Output is correct |
58 |
Correct |
483 ms |
105976 KB |
Output is correct |
59 |
Correct |
486 ms |
105776 KB |
Output is correct |
60 |
Correct |
34 ms |
47352 KB |
Output is correct |
61 |
Correct |
1143 ms |
109000 KB |
Output is correct |
62 |
Correct |
1139 ms |
108920 KB |
Output is correct |
63 |
Correct |
1129 ms |
108892 KB |
Output is correct |
64 |
Correct |
1129 ms |
108884 KB |
Output is correct |
65 |
Correct |
1154 ms |
109028 KB |
Output is correct |
66 |
Correct |
1228 ms |
109108 KB |
Output is correct |
67 |
Correct |
1142 ms |
108792 KB |
Output is correct |
68 |
Correct |
1133 ms |
108968 KB |
Output is correct |
69 |
Correct |
863 ms |
107764 KB |
Output is correct |
70 |
Correct |
33 ms |
47352 KB |
Output is correct |