AC代码:
const int N = 2e5 + 10;
int n, m, k;
int a[N], cnt1[N], cnt2[N];
int cnt, res, sum, ans;
int main()
{
int t;
sd(t);
while (t--)
{
sd(n);
rep(i, 1, n)
cnt1[i] = cnt2[i] = 0;
rep(i, 1, n)
{
sd(a[i]);
cnt1[a[i]]++;
}
rep(i, 1, n)
{
sum = a[i];
rep(j, i + 1, n)
{
sum += a[j];
if (sum > n)
break;
cnt2[sum] = true;
}
}
ans = 0;
rep(i, 1, n)
{
if (cnt1[i] && cnt2[i])
{
ans += cnt1[i];
}
}
pd(ans);
}
return 0;
}