cses

solution to cses exercise problems
git clone git://git.superpozycja.net/cses
Log | Files | Refs | README

commit 2a89c8b4a4fd8c39c50e0c60f029635caf25770d
parent 41b03d22ddc1807e9e1b865b3b68df5e17b71c2f
Author: superpozycja <anna@superpozycja.net>
Date:   Mon,  4 Nov 2024 00:05:40 +0100

solve subarray divisibility

Diffstat:
Asorting_and_searching/subarray_divisibility.cpp | 46++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 46 insertions(+), 0 deletions(-)

diff --git a/sorting_and_searching/subarray_divisibility.cpp b/sorting_and_searching/subarray_divisibility.cpp @@ -0,0 +1,46 @@ +#include <bits/stdc++.h> + +using namespace std; + +using ui = unsigned int; +using l = long; +using ul = unsigned long; +using ll = long long; +using ull = unsigned long long; + +using vi = vector<int>; +using vui = vector<ui>; +using vl = vector<l>; +using vul = vector<ul>; +using vll = vector<ll>; +using vull = vector<ull>; + + + +void solve() +{ + int n; + cin >> n; + + map<ll, int> a; + a[0] = 1; + ll lst = 0; + ll res = 0; + for (int i = 0; i < n; i++) { + int z; + cin >> z; + lst += z; + lst = (n + (lst % n)) % n; + res += a[lst]; + a[lst]++; + } + + cout << res << "\n"; +} + +int main() +{ + ios::sync_with_stdio(0); + cin.tie(0); + solve(); +}