Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int main() {
- ios_base::sync_with_stdio(false);
- cin.tie(0);
- int n, k;
- long long ans = 0;
- cin >> n >> k;
- vector<long long> vv(n);
- for(int i = 0; i < n; i++) {
- cin >> vv[i];
- }
- vector<long long> v;
- partial_sum(vv.begin(), vv.end(), back_inserter(v));
- for(auto itr = v.begin(); itr != v.end(); itr++) {
- if(itr == v.begin()) {
- auto l = lower_bound(itr, v.end(), k);
- auto r = upper_bound(itr, v.end(), k);
- if(*(r - 1) == k and *l == k) {
- ans += r - l;
- }
- } else {
- auto l = lower_bound(itr, v.end(), k + *itr);
- auto r = upper_bound(itr, v.end(), k + *itr);
- if(*(r - 1) == *itr and *(r - 1) - *(l - 1) != k) {
- continue;
- }
- if(*(r - 1) - *itr == k and *l - *itr == k) {
- ans += r - l;
- }
- }
- }
- cout << ans << "\n";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement