Pagini recente » Cod sursa (job #746735) | Cod sursa (job #2089246) | Cod sursa (job #2826612) | Cod sursa (job #1940975) | Cod sursa (job #3224253)
#include <bits/stdc++.h>
#define int long long
using namespace std;
ifstream fin("psir.in");
ofstream fout("psir.out");
const int mod = (1ll << 32) - 1;
const int nmax = 2005;
int v[nmax];
uint32_t d[nmax][nmax],sp[nmax][nmax];
int n;
inline void citire()
{
fin>>n;
int cnt=1;
map<int,int> norm;
for(int i=1; i<=n; i++)
{
fin>>v[i];
norm[v[i]] = 1;
}
for(auto [i,j] : norm)
{
norm[i] = cnt++;
}
for(int i=1; i<=n; i++)
{
v[i] = norm[v[i]];
}
}
signed main()
{
citire();
uint32_t total = 0;
for(int i=1; i<=n; i++)
{
uint32_t d[nmax] = {};
for(int j=1; j<i; j++)
{
d[v[j]] ++;
if(v[j] > v[i])
{
d[v[j]] += sp[j][v[i]-1];
}
else if(v[j] < v[i])
{
d[v[j]] += sp[j][nmax - 1] - sp[j][v[i]];
}
}
for(int j=1; j<nmax; j++)
{
total += d[j];
sp[i][j] = sp[i][j-1] + d[j];
}
}
fout<<total;
return 0;
}