Cod sursa(job #1397667)

Utilizator AlexNiuclaeNiculae Alexandru Vlad AlexNiuclae Data 23 martie 2015 17:54:44
Problema Divk Scor 90
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.98 kb
#include <cstdio>
#include <queue>
#include <algorithm>

#define Nmax 500010
#define Kmax 100000

using namespace std;

int n , k , a , b , sol , i , A , Mod;

int S[Kmax];

queue < pair < int , int > > baga , scoate;

int main()
{
    freopen("divk.in","r",stdin);
    freopen("divk.out","w",stdout);

    scanf("%d %d %d %d", &n, &k, &a, &b);

    baga.push(make_pair(a , 0));
    scoate.push(make_pair(b , 0));

    for (i = 1; i <= n; ++i)
    {
        while (baga.front().first == i && baga.size())
        {
            S[baga.front().second]++;
            baga.pop();
        }

        scanf("%d", &A);
        Mod = (Mod + A) % k;

        sol += S[Mod];

        while (scoate.front().first == i && scoate.size())
        {
            S[scoate.front().second]--;
            scoate.pop();
        }

        baga.push(make_pair(i + a , Mod));
        scoate.push(make_pair(i + b , Mod));
    }

    printf("%d\n", sol);

    return 0;
}