Pagini recente » Cod sursa (job #1178026) | Cod sursa (job #482004) | Cod sursa (job #1765255) | Cod sursa (job #1340316) | Cod sursa (job #2984629)
#include <fstream>
#include <vector>
#include <map>
using namespace std;
ifstream cin("psir.in");
ofstream cout("psir.out");
const int NMAX = 2000 + 123;
uint32_t dp[NMAX][NMAX];
int main() {
int n; cin >> n;
vector<int> v(n); for(auto &e : v) cin >> e;
map<int, int> norm; for(auto e : v) norm[e] = 1;
{ int cnt = 1; for(auto &e : norm) e.second = cnt++; }
for(auto &e : v) e = norm[e];
uint32_t rasp = 0;
for(int i = 0; i < n; i++) {
for(int j = 0; j < i; j++) {
uint32_t cnt = 1;
if(v[i] > v[j]) {
cnt += dp[j][NMAX - 1] - dp[j][v[i]];
}
if(v[i] < v[j]) {
cnt += dp[j][v[i] - 1];
}
dp[i][v[j]] += cnt;
}
for(int x = 0; x < NMAX; x++) {
rasp += dp[i][x];
if(x > 0) dp[i][x] += dp[i][x - 1];
}
}
cout << rasp << endl;
}