Krypton31's blog

By Krypton31, history, 3 years ago, In English

Can you please help me see my mistake, in Subarray Sums || It gives WA for 2 cases.


int main(){ FastIO; int n; ll x; cin>>n>>x; ll a[n]; ll prefix[n]; for(int i=0;i<n;i++){ cin>>a[i]; prefix[i] = a[i]; if(i>0) prefix[i]+=prefix[i-1]; } map<ll,ll>cache; int cnt =0; for(int i =0;i<n;i++){ cache[prefix[i]]+=1; if(prefix[i]==x and cache[0]==0) cnt+=1; else cnt+=cache[prefix[i]-x]; } cout<<cnt; return 0; }

Full text and comments »

  • Vote: I like it
  • +1
  • Vote: I do not like it