//ANMHLIJKTJIY! #pragma GCC optimize(2) #pragma GCC optimize("Ofast") #pragma GCC optimize("inline","fast-math","unroll-loops","no-stack-protector") #pragma GCC diagnostic error "-fwhole-program" #pragma GCC diagnostic error "-fcse-skip-blocks" #pragma GCC diagnostic error "-funsafe-loop-optimizations" #include <bits/stdc++.h> #define INF 1000000000 #define LINF 1000000000000000000 #define MOD 1000000007 #define mod 998244353 #define F first #define S second #define ll long long #define N 510 #define M 60000010 using namespace std; ll n,a[N],v[M],B=10000000,s1=0,s2=0,s3=0; vector<ll> qry[N]; int main(){ ll i,j,k; cin>>n; for(i=1;i<=n;i++) { cin>>a[i]; a[i]+=a[i-1]; } for(i=1;i<=n;i++) { for(j=0;j<i;j++) { if(a[i]==a[j]) { s3++; } } } memset(v,0,sizeof(v)); for(i=1;i<=n;i++) { for(j=0;j<i;j++) { v[a[i]-a[j]+B+B]++; } } for(i=1;i<=n;i++) { for(j=0;j<i;j++) { s2+=v[-(a[i]-a[j])*2+B+B]; } } for(i=1;i<=n;i++) { for(j=0;j<i;j++) { for(k=1;k<=n;k++) { qry[k-1].push_back(a[i]-a[j]+a[k]); } } } memset(v,0,sizeof(v)); for(i=0;i<n;i++) { for(j=1;j<=n;j++) { for(k=0;k<j;k++) { v[a[j]-a[k]-a[i]+B+B]++; } } for(j=0;j<qry[i].size();j++) { s1+=v[-qry[i][j]+B+B]; } } s2-=s3; s1-=s3; s1-=s2*3; cout<<s1/6<<'\n'; 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 | //ANMHLIJKTJIY! #pragma GCC optimize(2) #pragma GCC optimize("Ofast") #pragma GCC optimize("inline","fast-math","unroll-loops","no-stack-protector") #pragma GCC diagnostic error "-fwhole-program" #pragma GCC diagnostic error "-fcse-skip-blocks" #pragma GCC diagnostic error "-funsafe-loop-optimizations" #include <bits/stdc++.h> #define INF 1000000000 #define LINF 1000000000000000000 #define MOD 1000000007 #define mod 998244353 #define F first #define S second #define ll long long #define N 510 #define M 60000010 using namespace std; ll n,a[N],v[M],B=10000000,s1=0,s2=0,s3=0; vector<ll> qry[N]; int main(){ ll i,j,k; cin>>n; for(i=1;i<=n;i++) { cin>>a[i]; a[i]+=a[i-1]; } for(i=1;i<=n;i++) { for(j=0;j<i;j++) { if(a[i]==a[j]) { s3++; } } } memset(v,0,sizeof(v)); for(i=1;i<=n;i++) { for(j=0;j<i;j++) { v[a[i]-a[j]+B+B]++; } } for(i=1;i<=n;i++) { for(j=0;j<i;j++) { s2+=v[-(a[i]-a[j])*2+B+B]; } } for(i=1;i<=n;i++) { for(j=0;j<i;j++) { for(k=1;k<=n;k++) { qry[k-1].push_back(a[i]-a[j]+a[k]); } } } memset(v,0,sizeof(v)); for(i=0;i<n;i++) { for(j=1;j<=n;j++) { for(k=0;k<j;k++) { v[a[j]-a[k]-a[i]+B+B]++; } } for(j=0;j<qry[i].size();j++) { s1+=v[-qry[i][j]+B+B]; } } s2-=s3; s1-=s3; s1-=s2*3; cout<<s1/6<<'\n'; return 0; } |