#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for (int i=a;i<=b;i++)
#define rep2(i,a,b,c) for (int i=a;i<=b;i+=c)
#define rev(i,a,b) for (int i=a;i>=b;i--)
#define rev2(i,a,b,c) for (int i=a;i>=b;i-=c)
#define ii pair<int,int>
#define bit(i,j) ((i>>j)&1)
#define ull unsigned long long
#define pb push_back
#define ll long long
#define int long long
#define F first
#define S second
const int N=3e5+5;
const int mod=1e9+7;
const int MAX=1e9;
int n,res,a[N],dp[N],s[N*4],dem[N];
vector<int> uni;
void update(int id,int l,int r,int i,int val)
{
if(i>r||i<l)
return;
if(l==r)
{
s[id]+=val;
return;
}
int mid=(l+r)/2;
update(id*2,l,mid,i,val);
update(id*2+1,mid+1,r,i,val);
s[id]=s[id*2]+s[id*2+1];
}
int get(int id,int l,int r,int u,int v)
{
if(v<l||r<u)
return 0;
if(l>=u&&r<=v)
{
return s[id];
}
int mid=(l+r)/2;
return get(id*2,l,mid,u,v)+get(id*2+1,mid+1,r,u,v);
}
void solution()
{
cin>>n;
rep(i,1,n)
{
cin>>a[i];
uni.push_back(a[i]);
}
sort(uni.begin(),uni.end());
uni.resize(unique(uni.begin(),uni.end())-uni.begin());
rep(i,1,n) a[i]=lower_bound(uni.begin(),uni.end(),a[i])-uni.begin()+1;
rep(i,1,n)
{
dp[i]=get(1,1,n,0,a[i]-1);
update(1,1,n,a[i],1);
}
memset(s,0,sizeof(s));
rev(i,n,1){
res+=dp[i]*get(1,1,n,0,a[i]-1);
update(1,1,n,a[i],1);
}
cout<<res;
}
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
if(fopen("Mountains.inp","r")){freopen("Mountains.inp","r",stdin);freopen("Mountains.out","w",stdout);}
int test=1;
// cin>>test;
while(test--)
solution();
}
/*
*/
Compilation message
Mountains.cpp: In function 'int32_t main()':
Mountains.cpp:72:43: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
72 | if(fopen("Mountains.inp","r")){freopen("Mountains.inp","r",stdin);freopen("Mountains.out","w",stdout);}
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
Mountains.cpp:72:78: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
72 | if(fopen("Mountains.inp","r")){freopen("Mountains.inp","r",stdin);freopen("Mountains.out","w",stdout);}
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
9820 KB |
Output is correct |
2 |
Correct |
175 ms |
21568 KB |
Output is correct |
3 |
Correct |
184 ms |
21440 KB |
Output is correct |
4 |
Correct |
176 ms |
21628 KB |
Output is correct |
5 |
Correct |
174 ms |
21620 KB |
Output is correct |
6 |
Correct |
208 ms |
21588 KB |
Output is correct |
7 |
Correct |
172 ms |
21440 KB |
Output is correct |
8 |
Correct |
173 ms |
21436 KB |
Output is correct |
9 |
Correct |
164 ms |
21600 KB |
Output is correct |
10 |
Correct |
167 ms |
21588 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
122 ms |
17584 KB |
Output is correct |
2 |
Correct |
139 ms |
17596 KB |
Output is correct |
3 |
Correct |
111 ms |
17540 KB |
Output is correct |
4 |
Correct |
113 ms |
17596 KB |
Output is correct |
5 |
Correct |
115 ms |
17600 KB |
Output is correct |
6 |
Correct |
114 ms |
17496 KB |
Output is correct |
7 |
Correct |
128 ms |
17368 KB |
Output is correct |
8 |
Correct |
105 ms |
17600 KB |
Output is correct |
9 |
Correct |
114 ms |
17600 KB |
Output is correct |
10 |
Correct |
4 ms |
9820 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
122 ms |
17584 KB |
Output is correct |
2 |
Correct |
139 ms |
17596 KB |
Output is correct |
3 |
Correct |
111 ms |
17540 KB |
Output is correct |
4 |
Correct |
113 ms |
17596 KB |
Output is correct |
5 |
Correct |
115 ms |
17600 KB |
Output is correct |
6 |
Correct |
114 ms |
17496 KB |
Output is correct |
7 |
Correct |
128 ms |
17368 KB |
Output is correct |
8 |
Correct |
105 ms |
17600 KB |
Output is correct |
9 |
Correct |
114 ms |
17600 KB |
Output is correct |
10 |
Correct |
4 ms |
9820 KB |
Output is correct |
11 |
Correct |
157 ms |
17764 KB |
Output is correct |
12 |
Correct |
153 ms |
17860 KB |
Output is correct |
13 |
Correct |
151 ms |
17856 KB |
Output is correct |
14 |
Correct |
151 ms |
17620 KB |
Output is correct |
15 |
Correct |
163 ms |
17740 KB |
Output is correct |
16 |
Correct |
156 ms |
17856 KB |
Output is correct |
17 |
Correct |
160 ms |
17652 KB |
Output is correct |
18 |
Correct |
125 ms |
17852 KB |
Output is correct |
19 |
Correct |
127 ms |
17752 KB |
Output is correct |
20 |
Correct |
4 ms |
9820 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
9816 KB |
Output is correct |
2 |
Correct |
5 ms |
9820 KB |
Output is correct |
3 |
Correct |
7 ms |
9820 KB |
Output is correct |
4 |
Correct |
5 ms |
9816 KB |
Output is correct |
5 |
Correct |
4 ms |
9820 KB |
Output is correct |
6 |
Correct |
6 ms |
9820 KB |
Output is correct |
7 |
Correct |
4 ms |
9820 KB |
Output is correct |
8 |
Correct |
5 ms |
9804 KB |
Output is correct |
9 |
Correct |
4 ms |
9820 KB |
Output is correct |
10 |
Correct |
4 ms |
9820 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
9816 KB |
Output is correct |
2 |
Correct |
5 ms |
9820 KB |
Output is correct |
3 |
Correct |
7 ms |
9820 KB |
Output is correct |
4 |
Correct |
5 ms |
9816 KB |
Output is correct |
5 |
Correct |
4 ms |
9820 KB |
Output is correct |
6 |
Correct |
6 ms |
9820 KB |
Output is correct |
7 |
Correct |
4 ms |
9820 KB |
Output is correct |
8 |
Correct |
5 ms |
9804 KB |
Output is correct |
9 |
Correct |
4 ms |
9820 KB |
Output is correct |
10 |
Correct |
4 ms |
9820 KB |
Output is correct |
11 |
Correct |
12 ms |
10332 KB |
Output is correct |
12 |
Correct |
11 ms |
10420 KB |
Output is correct |
13 |
Correct |
11 ms |
10332 KB |
Output is correct |
14 |
Correct |
11 ms |
10288 KB |
Output is correct |
15 |
Correct |
12 ms |
10580 KB |
Output is correct |
16 |
Correct |
12 ms |
10332 KB |
Output is correct |
17 |
Correct |
11 ms |
10352 KB |
Output is correct |
18 |
Correct |
10 ms |
10332 KB |
Output is correct |
19 |
Correct |
9 ms |
10200 KB |
Output is correct |
20 |
Correct |
4 ms |
9820 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
122 ms |
17584 KB |
Output is correct |
2 |
Correct |
139 ms |
17596 KB |
Output is correct |
3 |
Correct |
111 ms |
17540 KB |
Output is correct |
4 |
Correct |
113 ms |
17596 KB |
Output is correct |
5 |
Correct |
115 ms |
17600 KB |
Output is correct |
6 |
Correct |
114 ms |
17496 KB |
Output is correct |
7 |
Correct |
128 ms |
17368 KB |
Output is correct |
8 |
Correct |
105 ms |
17600 KB |
Output is correct |
9 |
Correct |
114 ms |
17600 KB |
Output is correct |
10 |
Correct |
4 ms |
9820 KB |
Output is correct |
11 |
Correct |
157 ms |
17764 KB |
Output is correct |
12 |
Correct |
153 ms |
17860 KB |
Output is correct |
13 |
Correct |
151 ms |
17856 KB |
Output is correct |
14 |
Correct |
151 ms |
17620 KB |
Output is correct |
15 |
Correct |
163 ms |
17740 KB |
Output is correct |
16 |
Correct |
156 ms |
17856 KB |
Output is correct |
17 |
Correct |
160 ms |
17652 KB |
Output is correct |
18 |
Correct |
125 ms |
17852 KB |
Output is correct |
19 |
Correct |
127 ms |
17752 KB |
Output is correct |
20 |
Correct |
4 ms |
9820 KB |
Output is correct |
21 |
Correct |
261 ms |
18696 KB |
Output is correct |
22 |
Correct |
262 ms |
18624 KB |
Output is correct |
23 |
Correct |
248 ms |
18528 KB |
Output is correct |
24 |
Correct |
250 ms |
18620 KB |
Output is correct |
25 |
Correct |
249 ms |
18624 KB |
Output is correct |
26 |
Correct |
251 ms |
18528 KB |
Output is correct |
27 |
Correct |
249 ms |
18624 KB |
Output is correct |
28 |
Correct |
139 ms |
18624 KB |
Output is correct |
29 |
Correct |
136 ms |
18620 KB |
Output is correct |
30 |
Correct |
4 ms |
9820 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
9820 KB |
Output is correct |
2 |
Correct |
175 ms |
21568 KB |
Output is correct |
3 |
Correct |
184 ms |
21440 KB |
Output is correct |
4 |
Correct |
176 ms |
21628 KB |
Output is correct |
5 |
Correct |
174 ms |
21620 KB |
Output is correct |
6 |
Correct |
208 ms |
21588 KB |
Output is correct |
7 |
Correct |
172 ms |
21440 KB |
Output is correct |
8 |
Correct |
173 ms |
21436 KB |
Output is correct |
9 |
Correct |
164 ms |
21600 KB |
Output is correct |
10 |
Correct |
167 ms |
21588 KB |
Output is correct |
11 |
Correct |
122 ms |
17584 KB |
Output is correct |
12 |
Correct |
139 ms |
17596 KB |
Output is correct |
13 |
Correct |
111 ms |
17540 KB |
Output is correct |
14 |
Correct |
113 ms |
17596 KB |
Output is correct |
15 |
Correct |
115 ms |
17600 KB |
Output is correct |
16 |
Correct |
114 ms |
17496 KB |
Output is correct |
17 |
Correct |
128 ms |
17368 KB |
Output is correct |
18 |
Correct |
105 ms |
17600 KB |
Output is correct |
19 |
Correct |
114 ms |
17600 KB |
Output is correct |
20 |
Correct |
4 ms |
9820 KB |
Output is correct |
21 |
Correct |
157 ms |
17764 KB |
Output is correct |
22 |
Correct |
153 ms |
17860 KB |
Output is correct |
23 |
Correct |
151 ms |
17856 KB |
Output is correct |
24 |
Correct |
151 ms |
17620 KB |
Output is correct |
25 |
Correct |
163 ms |
17740 KB |
Output is correct |
26 |
Correct |
156 ms |
17856 KB |
Output is correct |
27 |
Correct |
160 ms |
17652 KB |
Output is correct |
28 |
Correct |
125 ms |
17852 KB |
Output is correct |
29 |
Correct |
127 ms |
17752 KB |
Output is correct |
30 |
Correct |
4 ms |
9820 KB |
Output is correct |
31 |
Correct |
5 ms |
9816 KB |
Output is correct |
32 |
Correct |
5 ms |
9820 KB |
Output is correct |
33 |
Correct |
7 ms |
9820 KB |
Output is correct |
34 |
Correct |
5 ms |
9816 KB |
Output is correct |
35 |
Correct |
4 ms |
9820 KB |
Output is correct |
36 |
Correct |
6 ms |
9820 KB |
Output is correct |
37 |
Correct |
4 ms |
9820 KB |
Output is correct |
38 |
Correct |
5 ms |
9804 KB |
Output is correct |
39 |
Correct |
4 ms |
9820 KB |
Output is correct |
40 |
Correct |
4 ms |
9820 KB |
Output is correct |
41 |
Correct |
12 ms |
10332 KB |
Output is correct |
42 |
Correct |
11 ms |
10420 KB |
Output is correct |
43 |
Correct |
11 ms |
10332 KB |
Output is correct |
44 |
Correct |
11 ms |
10288 KB |
Output is correct |
45 |
Correct |
12 ms |
10580 KB |
Output is correct |
46 |
Correct |
12 ms |
10332 KB |
Output is correct |
47 |
Correct |
11 ms |
10352 KB |
Output is correct |
48 |
Correct |
10 ms |
10332 KB |
Output is correct |
49 |
Correct |
9 ms |
10200 KB |
Output is correct |
50 |
Correct |
4 ms |
9820 KB |
Output is correct |
51 |
Correct |
261 ms |
18696 KB |
Output is correct |
52 |
Correct |
262 ms |
18624 KB |
Output is correct |
53 |
Correct |
248 ms |
18528 KB |
Output is correct |
54 |
Correct |
250 ms |
18620 KB |
Output is correct |
55 |
Correct |
249 ms |
18624 KB |
Output is correct |
56 |
Correct |
251 ms |
18528 KB |
Output is correct |
57 |
Correct |
249 ms |
18624 KB |
Output is correct |
58 |
Correct |
139 ms |
18624 KB |
Output is correct |
59 |
Correct |
136 ms |
18620 KB |
Output is correct |
60 |
Correct |
4 ms |
9820 KB |
Output is correct |
61 |
Correct |
301 ms |
22488 KB |
Output is correct |
62 |
Correct |
292 ms |
22464 KB |
Output is correct |
63 |
Correct |
304 ms |
22852 KB |
Output is correct |
64 |
Correct |
288 ms |
22476 KB |
Output is correct |
65 |
Correct |
300 ms |
22464 KB |
Output is correct |
66 |
Correct |
311 ms |
22460 KB |
Output is correct |
67 |
Correct |
300 ms |
22464 KB |
Output is correct |
68 |
Correct |
279 ms |
22464 KB |
Output is correct |
69 |
Correct |
259 ms |
18716 KB |
Output is correct |
70 |
Correct |
4 ms |
9816 KB |
Output is correct |