#include <bits/stdc++.h>
#define ll long long
#define F first
#define S second
#define N 300005
#define ii pair<int,int>
#define bit(i,j) ((i>>j)&1)
#define sz(i) (int)i.size()
#define endl '\n'
using namespace std;
int n;
int a[N];
namespace sub1
{
int res;
int bit[N][2];
void upd(int id,int v,int k)
{
for(id;id<=n;id+=(id&(-id)))
bit[id][k]+=v;
}
int get(int id,int k)
{
int t=0;
for(id;id>0;id-=((id&(-id))))
t+=bit[id][k];
return t;
}
void compress()
{
vector<int>v;
for(int i=1;i<=n;i++)
v.push_back(a[i]);
sort(v.begin(),v.end());
v.resize(unique(v.begin(),v.end())-v.begin());
for(int i=1;i<=n;i++)
a[i]=lower_bound(v.begin(),v.end(),a[i])-v.begin()+1;
}
void solve()
{
compress();
for(int i=2;i<=n;i++)
upd(a[i],1,1);
upd(a[1],1,0);
for(int i=2;i<n;i++)
{
res+=get(a[i]-1,0)*get(a[i]-1,1);
upd(a[i],-1,1);
upd(a[i],1,0);
}
cout<<res;
}
}
main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cin>>n;
for(int i=1;i<=n;i++)
cin>>a[i];
sub1::solve();
}
Compilation message
Mountains.cpp: In function 'void sub1::upd(int, int, int)':
Mountains.cpp:19:7: warning: statement has no effect [-Wunused-value]
19 | for(id;id<=n;id+=(id&(-id)))
| ^~
Mountains.cpp: In function 'int sub1::get(int, int)':
Mountains.cpp:25:7: warning: statement has no effect [-Wunused-value]
25 | for(id;id>0;id-=((id&(-id))))
| ^~
Mountains.cpp: At global scope:
Mountains.cpp:54:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
54 | main()
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
54 ms |
3648 KB |
Output is correct |
3 |
Correct |
53 ms |
3648 KB |
Output is correct |
4 |
Correct |
56 ms |
3648 KB |
Output is correct |
5 |
Correct |
54 ms |
3648 KB |
Output is correct |
6 |
Correct |
53 ms |
3644 KB |
Output is correct |
7 |
Correct |
54 ms |
3648 KB |
Output is correct |
8 |
Correct |
54 ms |
3644 KB |
Output is correct |
9 |
Correct |
53 ms |
3648 KB |
Output is correct |
10 |
Correct |
54 ms |
3648 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
66 ms |
4404 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
66 ms |
4404 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
66 ms |
4404 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
54 ms |
3648 KB |
Output is correct |
3 |
Correct |
53 ms |
3648 KB |
Output is correct |
4 |
Correct |
56 ms |
3648 KB |
Output is correct |
5 |
Correct |
54 ms |
3648 KB |
Output is correct |
6 |
Correct |
53 ms |
3644 KB |
Output is correct |
7 |
Correct |
54 ms |
3648 KB |
Output is correct |
8 |
Correct |
54 ms |
3644 KB |
Output is correct |
9 |
Correct |
53 ms |
3648 KB |
Output is correct |
10 |
Correct |
54 ms |
3648 KB |
Output is correct |
11 |
Incorrect |
66 ms |
4404 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |