Pagini recente » Cod sursa (job #838837) | Monitorul de evaluare | Cod sursa (job #1510429) | Cod sursa (job #1277441) | Cod sursa (job #1979552)
#include <fstream>
#include <iostream>
#include <queue>
#include <algorithm>
using namespace std;
const int nMax = 500005;
const int kMax = 100005;
int n, k, a, b;
int v[nMax];
int rest[nMax];
int ap[kMax]; //pozitiile elementului i in sum
void citire()
{
ifstream in("divk.in");
in >> n >> k >> a >> b;
for(int i = 1; i <= n; ++i)
in >> v[i];
in.close();
}
void rezolvare()
{
int st, dr, x;
int rasp = 0;
rest[0] = 0;
queue<int> q;
for(int i = 1; i <= n; ++i)
{
rest[i] = (rest[i-1] + v[i]) % k;
if(i >= a)
{
ap[rest[i-a]]++;
q.push(rest[i-a]);
}
if(q.size() > b - a + 1)
{
ap[q.front()]--;
q.pop();
}
rasp += ap[rest[i]];
}
ofstream out("divk.out");
out << rasp;
out.close();
}
int main()
{
citire();
rezolvare();
return 0;
}