// jd #include <bits/stdc++.h> #define int long long #define mp make_pair #define pb push_back #define ld long double #define pii pair<int,int> #define sz(x) (int)x.size() #define piii pair<pii,pii> #define precise cout<<fixed<<setprecision(10) #define st first #define nd second #define ins insert #define vi vector<int> #define BOOST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0) using namespace std; const int MAX=1<<20; const int mod=1e9+7; int a[MAX]; int pref[MAX]; set<int>pom; map<int,int>conv; int dp[MAX]; int kub(int x){ return (x/mod)%2; } int t[MAX*2][2][2]; void update(int u,int c,int ida,int idb){ for (t[u+=MAX][ida][idb]+=c;u>1;u>>=1){ t[u>>1][ida][idb]=(t[u][ida][idb]+t[u^1][ida][idb])%mod; } } int query(int u,int v,int ida,int idb){ int sum=0; for (u+=MAX,v+=MAX+1;u<v;u>>=1,v>>=1){ if (u&1)sum+=t[u++][ida][idb]; if (v&1)sum+=t[--v][ida][idb]; } return sum%mod; } const int STALA=1e6; int32_t main(){ BOOST; int n; cin>>n; pom.ins(0); for (int i=1;i<=n;i++)cin>>a[i],pref[i]=pref[i-1]+a[i],pom.ins(pref[i]%mod); int licznik=1; for (auto it:pom)conv[it]=licznik++; update(conv[0],1,0,0); dp[0]=1; // ida - kubelek , idb modulo 2 for (int i=1;i<=n;i++){ int modulus=pref[i]%mod; int kubel=kub(pref[i]); int wd1=conv[modulus]; int modwa=pref[i]%2; dp[i]+=query(1,wd1,kubel,modwa); dp[i]+=query(wd1+1,STALA,kubel,modwa^1); dp[i]+=query(1,wd1,kubel^1,modwa^1); dp[i]+=query(wd1+1,STALA,kubel^1,modwa); dp[i]%=mod; update(wd1,dp[i],kubel,pref[i]%2); } cout<<dp[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 | // jd #include <bits/stdc++.h> #define int long long #define mp make_pair #define pb push_back #define ld long double #define pii pair<int,int> #define sz(x) (int)x.size() #define piii pair<pii,pii> #define precise cout<<fixed<<setprecision(10) #define st first #define nd second #define ins insert #define vi vector<int> #define BOOST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0) using namespace std; const int MAX=1<<20; const int mod=1e9+7; int a[MAX]; int pref[MAX]; set<int>pom; map<int,int>conv; int dp[MAX]; int kub(int x){ return (x/mod)%2; } int t[MAX*2][2][2]; void update(int u,int c,int ida,int idb){ for (t[u+=MAX][ida][idb]+=c;u>1;u>>=1){ t[u>>1][ida][idb]=(t[u][ida][idb]+t[u^1][ida][idb])%mod; } } int query(int u,int v,int ida,int idb){ int sum=0; for (u+=MAX,v+=MAX+1;u<v;u>>=1,v>>=1){ if (u&1)sum+=t[u++][ida][idb]; if (v&1)sum+=t[--v][ida][idb]; } return sum%mod; } const int STALA=1e6; int32_t main(){ BOOST; int n; cin>>n; pom.ins(0); for (int i=1;i<=n;i++)cin>>a[i],pref[i]=pref[i-1]+a[i],pom.ins(pref[i]%mod); int licznik=1; for (auto it:pom)conv[it]=licznik++; update(conv[0],1,0,0); dp[0]=1; // ida - kubelek , idb modulo 2 for (int i=1;i<=n;i++){ int modulus=pref[i]%mod; int kubel=kub(pref[i]); int wd1=conv[modulus]; int modwa=pref[i]%2; dp[i]+=query(1,wd1,kubel,modwa); dp[i]+=query(wd1+1,STALA,kubel,modwa^1); dp[i]+=query(1,wd1,kubel^1,modwa^1); dp[i]+=query(wd1+1,STALA,kubel^1,modwa); dp[i]%=mod; update(wd1,dp[i],kubel,pref[i]%2); } cout<<dp[n]; return 0; } |