Skip to content

Instantly share code, notes, and snippets.

@gbrls
Created May 12, 2020 22:09
Show Gist options
  • Save gbrls/2d4cf0f95fe5e26fd2da05a988f9379d to your computer and use it in GitHub Desktop.
Save gbrls/2d4cf0f95fe5e26fd2da05a988f9379d to your computer and use it in GitHub Desktop.
obi-2019-f1-soma
#include <bits/stdc++.h>
#define int long long int
using namespace std;
const int M = 5e5+20;
int n,s;
int32_t main() {
cin>>n>>s;
int ans=0;
vector<int> vec(n);
for(int i=0;i<n;i++) cin>>vec[i];
for(int i=1;i<n;i++) vec[i] += vec[i-1];
for(int i=0;i<n;i++) {
if(vec[i]==s) ans++;
}
for(int i=0;i<n;i++) {
int c = vec[i];
int tar = c + s;
auto a = lower_bound(vec.begin()+i+1,vec.end(),tar);
auto b = upper_bound(vec.begin()+i+1,vec.end(),tar);
if(*a == tar) {
ans += b-a;
}
}
cout<<ans<<'\n';
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment