Cod sursa(job #2153977)

Utilizator Alex18maiAlex Enache Alex18mai Data 6 martie 2018 16:51:02
Problema Divk Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.87 kb
#include <fstream>
#include <vector>

using namespace std;

ifstream cin("divk.in");
ofstream cout("divk.out");

long long sp[500100];
vector<int> rest[100100];
pair<int, int> pnt[100100];

int main() {

    int n, a, b;
    long long k;
    cin >> n >> k >> a >> b;

    rest[0].push_back(0);

    long long ans = 0;

    for (int i = 1; i <= n; i++) {
        long long nr;
        cin >> nr;
        sp[i] = sp[i - 1] + nr;
        long long r = sp[i] % k;

        while (pnt[r].first < rest[r].size() && rest[r][pnt[r].first] < i - a) {
            pnt[r].first++;
        }

        while (pnt[r].second < rest[r].size() && rest[r][pnt[r].second] < i - b) {
            pnt[r].second++;
        }

        if (pnt[r].first < rest[r].size()){
            ans += 1LL * pnt[r].first - 1LL * pnt[r].second + 1LL;
        }

        rest[r].push_back(i);
    }

    cout<<ans;

    return 0;
}