三个区间分别是【A1-->A1】,【A3-->A6】,【A5-->A6】
AC代码:
#include<bits/stdc++.h> #define long long int #define N 200000 using namespace std; int a[N]; signed main() { int n,k,flag = 0; cin >> n >> k; for(int i = 1;i <= n;i++) { cin >> a[i]; if(a[i] == k) flag++; } for(int i = 1;i <= n;i++) { int temp = a[i]; for(int j = i + 1;j <= n;j++) { temp += a[j]; if(temp == k) flag++; } } cout << flag << endl; return 0; }