Cod sursa(job #2467098)

Utilizator PatrickCplusplusPatrick Kristian Ondreovici PatrickCplusplus Data 3 octombrie 2019 18:13:45
Problema Secventa 5 Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.17 kb
#include <bits/stdc++.h>
#define NMAX 1048576

using namespace std;

ifstream fin("secv5.in");
ofstream fout("secv5.out");

int n, l, r, fr[NMAX + 6], v[NMAX + 6], anterior = -1, z;
long long sum = 0, ans[100005];

void Add(long long x)
{
    long long rest = 0;
    for (int i = ans[0]; i >= 1; --i)
    {
        ans[i] = ans[i] + x % 10 + rest;
        rest = ans[i] / 10;
        ans[i] = ans[i] % 10;
        x = x / 10;
    }
    if (rest > 0)
    {
        ans[++ans[0]] = rest;
    }
}

int main()
{
    fin >> n >> l >> r;
    for (int i = 1; i <= n; ++i)
    {
        int x;
        fin >> x;
        if (anterior == x)
            fr[z]++;
        else
            v[++z] = x, fr[z] = 1;
        anterior = x;
    }
    if (z < l)
    {
        fout << 0;
        return 0;
    }
    ans[0] = 1;
    ans[1] = 0;
    for (int i = l; i <= z; ++i)
    {
        sum = sum + fr[i - l + 1];
        if (i - r > 0)
            sum = sum - fr[i - r + 1];
        long long x = 1LL * fr[i] * sum;
        Add(x);
    }
    for (int i = ans[0]; i >= 1; --i)
        fout << ans[i];
    fin.close();
    fout.close();
    return 0;
}