Cod sursa(job #611265)

Utilizator tzipleatudTudor Tiplea tzipleatud Data 31 august 2011 15:38:29
Problema Divk Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.45 kb
#include <fstream>

using namespace std;

ifstream f("divk.in");
ofstream g("divk.out");

int n,i,a,b,k,v[500001],w[500001],x;
long long s;

int main() {
    f >> n >> k >> a >> b;
    for (i=1;i<=n;i++) {
        f >> x;
        v[i]=(v[i-1]+x)%k;
    }
    s=0;
    for (i=a;i<=n;i++) {
        w[v[i-a]]++;
        if (i>b) w[v[i-b-1]]--;
        s+=w[v[i]];
    }
    g << s << '\n';
    f.close();g.close();
    return 0;
}