#include <bits/stdc++.h>
using namespace std;
const int SIZE1=505;
const int SIZE2=2e5;
const int SIZE3=5e4;
const int base=2e4;
int W[SIZE1];
int tab[SIZE2];
set<int> V[SIZE3];
//int V[SIZE3];
int main(){
int N,l=1,a;
long long s=0;
cin>>N;
//N=70;
for(int i=1;i<=N;i++){
cin>>W[i];
W[i]+=W[i-1];
}
for(int i=1;i<=N;i++){
for(int j=i;j<=N;j++){
a=W[j]-W[i-1];
tab[l]=a;
//V[a+base]++;
V[tab[l]+base].insert(l);
l++;
}
}
N=l-1;
for(int i=1;i<N;i++){
for(int j=i+1;j<=N;j++){
a=tab[i]+tab[j];
auto it=V[base-a].lower_bound(j+1);
//s+=V[base-a];
s+=distance(it,V[base-a].end());
}
}
cout<<s;
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 | #include <bits/stdc++.h> using namespace std; const int SIZE1=505; const int SIZE2=2e5; const int SIZE3=5e4; const int base=2e4; int W[SIZE1]; int tab[SIZE2]; set<int> V[SIZE3]; //int V[SIZE3]; int main(){ int N,l=1,a; long long s=0; cin>>N; //N=70; for(int i=1;i<=N;i++){ cin>>W[i]; W[i]+=W[i-1]; } for(int i=1;i<=N;i++){ for(int j=i;j<=N;j++){ a=W[j]-W[i-1]; tab[l]=a; //V[a+base]++; V[tab[l]+base].insert(l); l++; } } N=l-1; for(int i=1;i<N;i++){ for(int j=i+1;j<=N;j++){ a=tab[i]+tab[j]; auto it=V[base-a].lower_bound(j+1); //s+=V[base-a]; s+=distance(it,V[base-a].end()); } } cout<<s; return 0;} |
English