Pagini recente » Cod sursa (job #88835) | Cod sursa (job #1777469) | Cod sursa (job #1711189) | Cod sursa (job #1309097) | Cod sursa (job #1979545)
#include <cstdlib>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cassert>
using namespace std;
const int nMax = 500005;
const int kMax = 100005;
int n, k, a, b;
int v[nMax];
int rest[nMax];
vector<int> pos[kMax]; //pozitiile elementului i in sum
void citire()
{
freopen("divk.in", "r", stdin);
scanf("%d %d %d %d", &n, &k, &a, &b);
for(int i = 1; i <= n; ++i)
scanf("%d", &v[i]);
}
void rezolvare()
{
int st, dr, x;
int rasp = 0;
pos[0].push_back(0);
for(int i = 1; i <= n; ++i)
{
rest[i] = (rest[i-1] + v[i]) % k;
st = i - b;
dr = i - a;
x = upper_bound(pos[rest[i]].begin(), pos[rest[i]].end(), dr) -
lower_bound(pos[rest[i]].begin(), pos[rest[i]].end(), st);
rasp += x;
pos[rest[i]].push_back(i);
}
ofstream out("divk.out");
out << rasp;
out.close();
}
int main()
{
citire();
rezolvare();
return 0;
}