1 条题解
-
0
#include <bits/stdc++.h> #define int long long using namespace std; const int MOD = 1e9+7; const int N = 5e5+5; int n,dp[N]; string s; vector b[N<<1]; struct treelist{ int t[N]; int lowbit(int x){return x&(-x);} void add(int p,int x){for(;p<=n;p+=lowbit(p))(t[p]+=x)%=MOD;} int qry(int x){ int js=0; for(;x;x-=lowbit(x))js=(js+t[x])%MOD; return js; } } t[2]; signed main(){ ios::sync_with_stdio(false); cin.tie(0),cout.tie(0); cin>>n>>s; s=' '+s,dp[0]=1; int maxred=0,maxblue=1,l; for(int i = 1;i<=n;++i){ if(s[i]'X')dp[i]=dp[i-1]; if(s[i]'R')maxred=i; if(s[i]=='B')for(;maxblue<=i;++maxblue)b[(i<<1)-maxblue].push_back(maxblue); for(auto f:b[i])t[f&1].add(f,-dp[f-1]); l=(maxred<<1)-i+1; if(l<1)l=1; dp[i]+=(t[(i+1)&1].qry(i)-t[(i+1)&1].qry(l-1)+MOD)%MOD,dp[i]%=MOD; t[i&1].add(i,dp[i-1]); } cout<<dp[n]; return 0; }
- 1
信息
- ID
- 6910
- 时间
- 2000ms
- 内存
- 256MiB
- 难度
- 9
- 标签
- 递交数
- 20
- 已通过
- 3
- 上传者