Pagini recente » Cod sursa (job #1006357) | Cod sursa (job #1060688) | Cod sursa (job #440469) | Cod sursa (job #1079950) | Cod sursa (job #3314688)
//https://www.infoarena.ro/problema/divk
//#pragma GCC optimize ("Ofast")
//#pragma GCC optimize ("fast-math")
//#pragma GCC optimize ("unroll-loops")
//#define _USE_MATH_DEFINES
#include <iostream>
#include <fstream>
//#include <vector>
//#include <cstring>
//#include <cmath>
//#include <bitset>
//#include <queue>
//#include <stack>
//#include <utility>
//#include <algorithm>
//#include <string>
//#include <map>
//#include <unordered_map>
//#include <set>
//#include <unordered_set>
//#include <cstdint>
//#include <climits>
//#include <iomanip>
//#include <cstdio>
//#include <tuple>
using namespace std;
const int NRMAX = 500000;
const int KMAX = 100000;
int64_t sp[NRMAX + 1];
int fr[KMAX + 1];
template<typename T>
class FastIO
{
private:
ifstream& fin;
ofstream& fout;
static constexpr int IN_BUF_SIZE = 262144;
static constexpr int OUT_BUF_SIZE = 262144;
char inBuf[IN_BUF_SIZE];
int inPos = IN_BUF_SIZE, inBytes = IN_BUF_SIZE;
char outBuf[OUT_BUF_SIZE];
int outPos = 0;
inline char getChar()
{
if (inPos == inBytes)
{
fin.read(inBuf, IN_BUF_SIZE);
inBytes = fin.gcount();
inPos = 0;
if (inBytes == 0)
return -1;
}
return inBuf[inPos++];
}
inline void writeChar(char c)
{
if (outPos == OUT_BUF_SIZE)
{
fout.write(outBuf, outPos);
outPos = 0;
}
outBuf[outPos++] = c;
}
public:
FastIO(ifstream& finStream, ofstream& foutStream) : fin(finStream), fout(foutStream) {}
T readInt()
{
char c;
bool neg = false;
do
{
c = getChar();
if (c == -1)
return -1;
} while ((c < '0' || c > '9') && c != '-');
if (c == '-')
{
neg = true;
c = getChar();
}
T res = 0;
while (c >= '0' && c <= '9')
{
res = res * 10 + (c - '0');
c = getChar();
}
return neg ? -res : res;
}
void writeInt(T x)
{
if (x < 0)
{
writeChar('-');
x = -x;
}
char temp[20];
int len = 0;
do
{
temp[len++] = '0' + x % 10;
x /= 10;
} while (x);
while (len--)
writeChar(temp[len]);
}
void flush()
{
if (outPos > 0)
{
fout.write(outBuf, outPos);
outPos = 0;
}
}
};
int main()
{
ifstream fin("divk.in");
ofstream fout("divk.out");
FastIO<int64_t> io(fin, fout);
int n, k, a, b, i;
int64_t rez = 0;
n = io.readInt();
k = io.readInt();
a = io.readInt();
b = io.readInt();
for (i = 1; i <= n; ++i)
{
int x = io.readInt();
sp[i] = (sp[i - 1] + x) % k;
// Pozitia pe care adaug i-a
int adg = i - a;
if (adg >= 0)
++fr[sp[i - a]];
// Pozitia de pe care scot i-b-1
int elim = i - b - 1;
if (elim >= 0)
--fr[sp[i - b - 1]];
rez += fr[sp[i]];
}
io.writeInt(rez);
io.flush();
return 0;
}