This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
const int nmax=1e5+42,mod=1e9+7;
int n,q;
int inp[nmax];
int LHS,RHS;
int dp[nmax][10];//digits, first digit
int query(int l,int r)
{
LHS=l;
RHS=r;
int ret=0,prv=0;
for(int i=LHS;i<=RHS;i++)
{
for(int cur=0;cur<inp[i];cur++)
if(prv==1&&cur==3)continue;
else
{
ret=(ret+dp[RHS-i][cur])%mod;
}
if(prv==1&&inp[i]==3)break;
prv=inp[i];
if(i==RHS)ret=(ret+1)%mod;
}
return ret;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie();
cout.tie();
cin>>n>>q;
for(int i=0;i<=9;i++)
{
dp[0][i]=1;
}
for(int pos=1;pos<=n;pos++)
{
for(int frst=0;frst<=9;frst++)
{
for(int prv=0;prv<=9;prv++)
if(frst==1&&prv==3)continue;
else
{
dp[pos][frst]=(dp[pos][frst]+dp[pos-1][prv])%mod;
}
//cout<<pos<<" "<<frst<<" -> "<<dp[pos][frst]<<endl;
}
}
for(int i=1;i<=n;i++)
{
char c;
cin>>c;
inp[i]=c-'0';
}
cout<<query(1,n)<<"\n";
for(int i=1;i<=q;i++)
{
int type;
cin>>type;
if(type==2)
{
int pos,val;
cin>>pos>>val;
inp[pos]=val;
}
else
{
int l,r;
cin>>l>>r;
cout<<query(l,r)<<"\n";
}
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |