Cod sursa(job #2408197)

Utilizator adimiclaus15Miclaus Adrian Stefan adimiclaus15 Data 17 aprilie 2019 18:28:31
Problema Divk Scor 90
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.07 kb
#include <iostream>
#include <fstream>
#include <vector>
# define verf ++poz == hg ? f.read (ch, hg), poz = 0 : 0
using namespace std;
ifstream f("divk.in");
ofstream g("divk.out");
int n,k,a,b,x,poz,s;
vector <int> v[100005];
const int hg = 1 << 13;
char ch[hg];
inline void cit ( int &x ) {
    if (ch[0] == '\0') f.read (ch, hg) ;
    else for (; ch[poz] < '0' || ch[poz] > '9' ; verf) ;
    for (x = 0 ; ch[poz] >= '0' && ch[poz] <= '9' ; x = x * 10 + ch[poz] - '0', verf) ;
}
int Count(int d)
{
    int i,j,p,nr;
    nr=0;
    for(p=0;p<k;p++)
    {
        j=0;
        for(i=0;i<v[p].size();i++)
        {
            while(j<v[p].size() && v[p][j]-v[p][i]<=d)
            {
                j++;
            }
            nr=nr+j-i-1;
        }
    }
    return nr;
}
int main()
{
    int i;
    //f>>n>>k>>a>>b;
    cit(n);
    cit(k);
    cit(a);
    cit(b);
    v[0].push_back(0);
    for(i=1;i<=n;i++)
    {
        //f>>x;
        cit(x);
        s=(s+x)%k;
        v[s].push_back(i);
    }
    g<<Count(b)-Count(a-1);
    return 0;
}