#include <bits/stdc++.h> #define ll long long #define ld long double #define endl '\n' #define st first #define nd second #define pb push_back #define sz(x) (int)(x).size() #define all(x) (x).begin(), (x).end() using namespace std; int inf=1000000007; ll infl=1000000000000000007; ll mod=1000000007; ll mod1=998244353; const int N=507,S=20007; const int T=3*N*S; int ile[N*S*6]; int a[N]; int p[N]; signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin>>n; ll ans=0; for(int i=1;i<=n;i++) { cin>>a[i]; p[i]=p[i-1]+a[i]; } //aaa for(int i=1;i<=n;i++) { ile[3*p[i-1]+T]++; for(int j=i+1;j<=n;j++) { for(int l=j+1;l<=n;l++) { ans+=ile[(p[i]+p[j]+p[l])+T]; } } } memset(ile,0,sizeof ile); //aa<b for(int i=1;i<=n;i++) { for(int j=i;j<=n;j++) { for(int l=j+1;l<=n;l++) { ile[2*p[i-1]-p[j]-p[l]+T]++; } } for(int j=i+1;j<=n;j++) { ans+=ile[-(p[i]-p[j])+T]; } } memset(ile,0,sizeof ile); //a<bb for(int i=1;i<=n;i++) { for(int j=i;j<=n;j++) ile[p[i-1]-p[j]+T]++; for(int j=i+1;j<=n;j++) { for(int l=j+1;l<=n;l++) { ans+=ile[-(2*p[i]-p[j]-p[l])+T]; } } } memset(ile,0,sizeof ile); //a<b<c for(int i=1;i<=n;i++) { for(int j=i-2;j>=0;j--) { for(int l=j+1;l<=n;l++) { ile[p[i-1]+p[j]-p[l]+T]++; } } //c>=y for(int j=i;j<=n;j++) { for(int l=j+1;l<=n;l++) { ans+=ile[-(p[j]-p[i]-p[l])+T]; } } //c<y for(int j=i+1;j<=n;j++) { for(int l=i+1;l<=n;l++) { ans+=ile[-(p[i]-p[j]-p[l])+T]; } } } cout<<ans; return 0; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 | #include <bits/stdc++.h> #define ll long long #define ld long double #define endl '\n' #define st first #define nd second #define pb push_back #define sz(x) (int)(x).size() #define all(x) (x).begin(), (x).end() using namespace std; int inf=1000000007; ll infl=1000000000000000007; ll mod=1000000007; ll mod1=998244353; const int N=507,S=20007; const int T=3*N*S; int ile[N*S*6]; int a[N]; int p[N]; signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin>>n; ll ans=0; for(int i=1;i<=n;i++) { cin>>a[i]; p[i]=p[i-1]+a[i]; } //aaa for(int i=1;i<=n;i++) { ile[3*p[i-1]+T]++; for(int j=i+1;j<=n;j++) { for(int l=j+1;l<=n;l++) { ans+=ile[(p[i]+p[j]+p[l])+T]; } } } memset(ile,0,sizeof ile); //aa<b for(int i=1;i<=n;i++) { for(int j=i;j<=n;j++) { for(int l=j+1;l<=n;l++) { ile[2*p[i-1]-p[j]-p[l]+T]++; } } for(int j=i+1;j<=n;j++) { ans+=ile[-(p[i]-p[j])+T]; } } memset(ile,0,sizeof ile); //a<bb for(int i=1;i<=n;i++) { for(int j=i;j<=n;j++) ile[p[i-1]-p[j]+T]++; for(int j=i+1;j<=n;j++) { for(int l=j+1;l<=n;l++) { ans+=ile[-(2*p[i]-p[j]-p[l])+T]; } } } memset(ile,0,sizeof ile); //a<b<c for(int i=1;i<=n;i++) { for(int j=i-2;j>=0;j--) { for(int l=j+1;l<=n;l++) { ile[p[i-1]+p[j]-p[l]+T]++; } } //c>=y for(int j=i;j<=n;j++) { for(int l=j+1;l<=n;l++) { ans+=ile[-(p[j]-p[i]-p[l])+T]; } } //c<y for(int j=i+1;j<=n;j++) { for(int l=i+1;l<=n;l++) { ans+=ile[-(p[i]-p[j]-p[l])+T]; } } } cout<<ans; return 0; } |