思路:dp
代码:
#include<bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define ls rt<<1,l,m #define rs rt<<1|1,m+1,r const int INF=0x3f3f3f3f; const int N=3e5+5; ll dp[N]={0}; int main() { ios::sync_with_stdio(false); cin.tie(0); string s; cin>>s; ll ans=0; if((s[0]-'0')%4==0)dp[0]=1; for(int i=1;i<s.size();i++) { int x=s[i]-'0'; if(x%4==0)dp[i]=dp[i-1]+1; else dp[i]=dp[i-1]; int y=s[i-1]-'0'; int n=y*10+x; if(n%4==0)dp[i]+=i; } cout<<dp[s.size()-1]<<endl; return 0; }