E n^2 可过...
简单优化一下即可...,幽默数据
#include<bits/stdc++.h> using namespace std; typedef long long ll; int n; ll a[214514]; ll s[214514],ss[214514]; ll cnt; ll ans; int main() { cin>>n; for(int i=1;i<=n;i++) { cin>>a[i]; s[i]=s[i-1]+a[i]; ss[i]=ss[i-1]+(a[i]>0); } cnt=s[n]/3; if(cnt*3!=s[n]) { cout<<0; return 0; } for(int i=1;i<=n;i++) { if(s[i]==cnt&&ss[i]>0) { for(int j=i+1;j<=n;j++) if(ss[j]-ss[i]>0&&ss[n]-ss[j]>0) if(s[j]-s[i]==cnt) ans++; } } cout<<ans; return 0; }