#include <vector> #include <utility> #include <cstdio> #define REP(a, n) for (int a = 0; a < (n); ++a) #define FOR(a, b, c) for (int a = (b); a <= (c); ++a) #define FORD(a, b, c) for (int a = (b); a >= (c); --a) using namespace std; typedef long long LL; /////////////////////////// int N; int ciag[500], sumaod[505]; int ile_o[60'000'010], *ile = ile_o+30'000'005; int zwykle_o[60'000'010], *zwykle = zwykle_o+30'000'005; LL res = 0; int main() { scanf("%d", &N); REP(a, N) scanf("%d", &ciag[a]); FORD(a, N-1, 0) sumaod[a] = sumaod[a+1]+ciag[a]; FORD(c, N-1, 0) { int d = c; REP(e, N) FOR(f, e, N-1) ile[-sumaod[d+1]+sumaod[e]-sumaod[f+1]]++; REP(a, N) FOR(b, a, N-1) res += ile[-(sumaod[a]-sumaod[b+1]+sumaod[c])]; } REP(e, N) FOR(f, e, N-1) zwykle[sumaod[e]-sumaod[f+1]]++; REP(a, N) FOR(b, a, N-1) res -= 3*zwykle[-2*(sumaod[a]-sumaod[b+1])]; REP(a, N) FOR(b, a, N-1) if (sumaod[a]-sumaod[b+1]==0) res+=2; printf("%lld\n", res/6); }
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 | #include <vector> #include <utility> #include <cstdio> #define REP(a, n) for (int a = 0; a < (n); ++a) #define FOR(a, b, c) for (int a = (b); a <= (c); ++a) #define FORD(a, b, c) for (int a = (b); a >= (c); --a) using namespace std; typedef long long LL; /////////////////////////// int N; int ciag[500], sumaod[505]; int ile_o[60'000'010], *ile = ile_o+30'000'005; int zwykle_o[60'000'010], *zwykle = zwykle_o+30'000'005; LL res = 0; int main() { scanf("%d", &N); REP(a, N) scanf("%d", &ciag[a]); FORD(a, N-1, 0) sumaod[a] = sumaod[a+1]+ciag[a]; FORD(c, N-1, 0) { int d = c; REP(e, N) FOR(f, e, N-1) ile[-sumaod[d+1]+sumaod[e]-sumaod[f+1]]++; REP(a, N) FOR(b, a, N-1) res += ile[-(sumaod[a]-sumaod[b+1]+sumaod[c])]; } REP(e, N) FOR(f, e, N-1) zwykle[sumaod[e]-sumaod[f+1]]++; REP(a, N) FOR(b, a, N-1) res -= 3*zwykle[-2*(sumaod[a]-sumaod[b+1])]; REP(a, N) FOR(b, a, N-1) if (sumaod[a]-sumaod[b+1]==0) res+=2; printf("%lld\n", res/6); } |