Cod sursa(job #2984629)

Utilizator oskar01oskar the boss oskar01 Data 24 februarie 2023 16:23:46
Problema P-sir Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.9 kb
#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;
}