Untitled
unknown
plain_text
10 months ago
677 B
2
Indexable
#include <iostream> #include <unordered_map> using namespace std; int i, n, k, tmp, a; long long cnt = 0; unordered_map<int,int> mp; unordered_map<int,int>::iterator it; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cin >> n >> k; a = 0; for(i = 0; i < n; i++){ mp[a]++; cin >> tmp; tmp = (tmp%k + a) % k; if(tmp < 0) tmp += k; a = tmp; } mp[a]++; for(it = mp.begin(); it != mp.end(); it++){ tmp = (*it).second; if(tmp > 1) cnt += 1ll*tmp*(tmp-1)/2; } cout << cnt << endl; return 0; }
Editor is loading...
Leave a Comment