#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 |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
37 ms |
896 KB |
Output is correct |
2 |
Correct |
50 ms |
1012 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
37 ms |
896 KB |
Output is correct |
2 |
Correct |
50 ms |
1012 KB |
Output is correct |
3 |
Correct |
67 ms |
4344 KB |
Output is correct |
4 |
Correct |
66 ms |
4088 KB |
Output is correct |
5 |
Correct |
75 ms |
4472 KB |
Output is correct |
6 |
Correct |
81 ms |
4984 KB |
Output is correct |
7 |
Correct |
85 ms |
4992 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
37 ms |
896 KB |
Output is correct |
8 |
Correct |
50 ms |
1012 KB |
Output is correct |
9 |
Correct |
20 ms |
896 KB |
Output is correct |
10 |
Correct |
28 ms |
896 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
37 ms |
896 KB |
Output is correct |
8 |
Correct |
50 ms |
1012 KB |
Output is correct |
9 |
Correct |
67 ms |
4344 KB |
Output is correct |
10 |
Correct |
66 ms |
4088 KB |
Output is correct |
11 |
Correct |
75 ms |
4472 KB |
Output is correct |
12 |
Correct |
81 ms |
4984 KB |
Output is correct |
13 |
Correct |
85 ms |
4992 KB |
Output is correct |
14 |
Correct |
20 ms |
896 KB |
Output is correct |
15 |
Correct |
28 ms |
896 KB |
Output is correct |
16 |
Correct |
49 ms |
3960 KB |
Output is correct |
17 |
Correct |
48 ms |
3960 KB |
Output is correct |
18 |
Correct |
55 ms |
4472 KB |
Output is correct |
19 |
Correct |
61 ms |
4856 KB |
Output is correct |
20 |
Correct |
62 ms |
4856 KB |
Output is correct |