Sometimes I feel like I'm a train of thought.
This question first said to ask is the number of good interval, a good interval satisfies the condition: 1, the number of bits 1 and 2 for even, W[i] for a[i] binary 1, sum[i] = w[1] + ... + w[i], for any position l-r] < SUM[R]-sum[l]-w[j]
Set a dp[n][2] array, dp[i][0] represents the end of I, the number of binary 1 in the interval and the number of intervals for even numbers
DP[I][1] Represents the end of I, the number of binary 1 in the interval and the number of odd intervals
Then use Dp[i][0]-all the intervals that do not satisfy the condition 2, sum all the satisfied intervals
This 1<=a[i] <= 1e8 1e8 is smaller than this long long, 602 binary can be saved, so the L-r this interval the largest w[j] is actually 60, the smallest w[i] is 1, so when you this interval length is greater than 60, must meet the conditions 2
With my incredibly ugly AC code.
#include <iostream>#include<queue>#include<cstring>#include<vector>#include<cstdio>#include<cmath>#include<map>#include<string>using namespacestd;#definell Long Long#defineSe Second#defineFi firstintN;Const intMAXN =300010;Long LongARR[MAXN];intW[MAXN];intSUM[MAXN];intdp[maxn][2];intMain () {memset (W,0,sizeof(w)); scanf ("%d",&N); for(inti =1; I <= N; ++i) {scanf ("%lld", arr+i); Long LongK =1; for(intj =0; J < +; ++j, K <<=1) { if(K &Arr[i]) w[i]++; } //cout << w[i] << Endl;} dp[1][0] = dp[1][1] = dp[0][0] = dp[0][1] =0; for(inti =2; I <= N; ++i) {//cout << w[i] << Endl; if(W[i]%2==1) {dp[i][0] = dp[i-1][1]+ (w[i-1]%2); dp[i][1] = dp[i-1][0]+! (w[i-1]%2); } Else{dp[i][0] = dp[i-1][0]+! (w[i-1]%2); dp[i][1] = dp[i-1][1]+ (w[i-1]%2); }} ll ans=0; for(inti =2; I <= N; ++i) {ll add=0; ll MX=W[i]; ll Sum=W[i]; for(intj = I1; J >=1&& i-j<= -; --j) {if(MX < w[j]) MX =W[j]; Sum+=W[j]; if(mx > sum-mx && sum%2==0) Add--; } //cout << dp[i][0] << Endl; //cout << add << endl;Add + = dp[i][0]; Ans+=add; } printf ("%lld\n", ans);}
Codeforces Round #512 E-vasya and good sequences