#include<bits/stdc++.h> #define st first #define nd second #define pb(x) push_back(x) #define pp(x) pop_back(x) #define mp(a, b) make_pair(a, b) #define all(x) (x).begin(), (x).end() #define rev(x) reverse(all(x)) #define sor(x) sort(all(x)) #define sz(x) (int)(x).size() #define rsz(x) resize(x) using namespace std; typedef long long ll; typedef long double ld; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<int> vi; typedef vector<pii > vii; typedef vector<ll> vl; typedef vector<pll> vll; typedef string str; #define BOOST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); const int mx_N = 1e5*3+10; const ll md = 1e9+7; const int p2 = 1<<19; map<ll,ll>M;//reszta -> nr reszty ll pre[mx_N]; ll pre2[mx_N]; ll tre[2][2*p2 +10]; ll suma(ll a, ll b,int typ) { ll sum = 0; a+=p2; b+=p2; a--; b++; while(a/2 != b/2) { if(a%2 == 0) sum+=tre[typ][a+1]; if(b%2 == 1) sum+=tre[typ][b-1]; a>>=1; b>>=1; } return sum%md; } void dodaj(ll ind, int typ, ll val ) { ind+=p2; tre[typ][ind] = (tre[typ][ind]+val)%md; ind>>=1; while(ind > 0) { tre[typ][ind] = (tre[typ][ind<<1] +tre[typ][(ind<<1) + 1])%md; ind>>=1; } } void nowy(ll a) { int typ = a%2; int ind = M[a]; ll addit = (suma(0 , ind , typ) + suma(ind+1 , p2-1 , 1-typ))%md; dodaj(ind , typ, addit); } int main() { BOOST int n; cin>>n; ll temp; for(int i = 1 ; i <= n ; i++) { cin>>pre[i]; pre[i] = (pre[i]+pre[i-1])%md; pre2[i] = pre[i]; } sort(pre2+1,pre2+n+1); M[pre2[1]] = 0; ll ind = 1; for(int i = 2 ; i <= n ; i++) { if(pre2[i] != pre2[i-1]) { M[pre2[i]] = ind; ind++; } } dodaj(0 , 0 , 1); for(int i = 1 ; i <= n ; i++) { nowy(pre[i]); } cout<<tre[pre[n]%2][M[pre[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 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 | #include<bits/stdc++.h> #define st first #define nd second #define pb(x) push_back(x) #define pp(x) pop_back(x) #define mp(a, b) make_pair(a, b) #define all(x) (x).begin(), (x).end() #define rev(x) reverse(all(x)) #define sor(x) sort(all(x)) #define sz(x) (int)(x).size() #define rsz(x) resize(x) using namespace std; typedef long long ll; typedef long double ld; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<int> vi; typedef vector<pii > vii; typedef vector<ll> vl; typedef vector<pll> vll; typedef string str; #define BOOST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); const int mx_N = 1e5*3+10; const ll md = 1e9+7; const int p2 = 1<<19; map<ll,ll>M;//reszta -> nr reszty ll pre[mx_N]; ll pre2[mx_N]; ll tre[2][2*p2 +10]; ll suma(ll a, ll b,int typ) { ll sum = 0; a+=p2; b+=p2; a--; b++; while(a/2 != b/2) { if(a%2 == 0) sum+=tre[typ][a+1]; if(b%2 == 1) sum+=tre[typ][b-1]; a>>=1; b>>=1; } return sum%md; } void dodaj(ll ind, int typ, ll val ) { ind+=p2; tre[typ][ind] = (tre[typ][ind]+val)%md; ind>>=1; while(ind > 0) { tre[typ][ind] = (tre[typ][ind<<1] +tre[typ][(ind<<1) + 1])%md; ind>>=1; } } void nowy(ll a) { int typ = a%2; int ind = M[a]; ll addit = (suma(0 , ind , typ) + suma(ind+1 , p2-1 , 1-typ))%md; dodaj(ind , typ, addit); } int main() { BOOST int n; cin>>n; ll temp; for(int i = 1 ; i <= n ; i++) { cin>>pre[i]; pre[i] = (pre[i]+pre[i-1])%md; pre2[i] = pre[i]; } sort(pre2+1,pre2+n+1); M[pre2[1]] = 0; ll ind = 1; for(int i = 2 ; i <= n ; i++) { if(pre2[i] != pre2[i-1]) { M[pre2[i]] = ind; ind++; } } dodaj(0 , 0 , 1); for(int i = 1 ; i <= n ; i++) { nowy(pre[i]); } cout<<tre[pre[n]%2][M[pre[n]]]; return 0; } |