Advertisement
Guest User

Untitled

a guest
Nov 18th, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4. map <int, int> cnt;
  5. int n, x, y;
  6.  
  7. int32_t main()
  8. {
  9. cin >> n >> x >> y;
  10. int a [n];
  11. cin >> a [0];
  12. a [0] = a [0] % x;
  13. for (int i = 1; i < n; i++)
  14. {
  15. cin >> a [i];
  16. a [i] = (a [i] + a [i - 1]) % x;
  17. }
  18. int ans = 0;
  19. for (int i = 0; i < n; i++)
  20. {
  21. if (a [i] == y)
  22. {
  23. ans += cnt [0] + 1;
  24. cnt [a [i]]++;
  25. continue;
  26. }
  27. if (a [i] > y)
  28. {
  29. ans += cnt [a [i] - y];
  30. cnt [a [i]]++;
  31. continue;
  32. }
  33. if (a [i] < y)
  34. {
  35. ans += cnt [a [i] + x - y];
  36. cnt [a [i]]++;
  37. continue;
  38. }
  39. }
  40. cout << ans;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement