#include <bits/stdc++.h>
#include <chrono>
#define ll long long int
#define endl '\n'
#define vn vector<ll>
#define vi vector<pair <ll,ll>>
using namespace std;
using namespace std::chrono;
const int MAX_N = 1e9 + 7;
#define pii pair<ll,ll>
const ll INF = 0x3f3f3f3f3f3f3f3f;
#define pb push_back
#define srt(vp) sort(vp.begin(), vp.end())
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
auto start = high_resolution_clock::now();
ll n;
cin>>n;
vn v(n);
for (auto&x:v)cin>>x;
ll ans = 0;
vn a;
vn b = v;
a.pb(v[0]);
b.erase(b.begin());
for (int i=1;i<n-1;i++){
a.pb(v[i]);
sort(a.begin(),a.end());
auto it = lower_bound(a.begin(),a.end(),v[i]);
ll num1 = it - a.begin();
sort(b.begin(),b.end());
auto it2 = lower_bound(b.begin(),b.end(),v[i]);
ll num2 = it2-b.begin();
ans += num2*num1;
auto it3 = find(b.begin(),b.end(),v[i]);
b.erase(it3);//gpt for syntax
}
cout<<ans<<endl;
auto stop = high_resolution_clock::now();
auto duration = duration_cast<microseconds>(stop - start);
//cout << "Time taken by function: " << duration.count() << " microseconds" << endl;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |