Pagini recente » Cod sursa (job #2225468) | Cod sursa (job #85631) | Cod sursa (job #1299286) | Cod sursa (job #1308145) | Cod sursa (job #3224248)
#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],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();
int total = 0;
for(int i=1; i<=n; i++)
{
for(int j=1; j<i; j++)
{
d[i][v[j]] ++;
if(v[j] > v[i])
{
d[i][v[j]] += sp[j][v[i]-1];
}
else if(v[j] < v[i])
{
d[i][v[j]] += sp[j][nmax - 1] - sp[j][v[i]];
}
d[i][v[j]] &= mod;
}
for(int j=1; j<nmax; j++)
{
total += d[i][j];
total &= mod;
sp[i][j] = sp[i][j-1] + d[i][j];
sp[i][j] &= mod;
}
}
fout<<total;
return 0;
}