#include <bits/stdc++.h>
#define EQ 0
#define LE 1
using namespace std;
const int MOD = 1e9+7;
const int NMAX = 1e4+2;
const int SIGMA = 10;
int n,q,t,l,r,pos,val,dp[2][SIGMA][NMAX];
string s;
int countWays(string str){
memset(dp, 0, sizeof(dp));
dp[EQ][0][0] = 1;
for(int i = 1; i < str.size(); i++){
for(auto state : {EQ, LE}){
if(state == EQ){
for(int dig = 0; dig <= 9; dig++){
if(dig < str[i]-'0'){
/// LE
for(int lst = 0; lst <= 9; lst++){
if(lst == 1 && dig == 3){
continue;
}
dp[LE][dig][i] += dp[EQ][lst][i-1];
dp[LE][dig][i] %= MOD;
}
}else if(dig == str[i]-'0'){
/// EQ
for(int lst = 0; lst <= 9; lst++){
if(lst == 1 && dig == 3){
continue;
}
dp[EQ][dig][i] += dp[EQ][lst][i-1];
dp[EQ][dig][i] %= MOD;
}
}
}
}else{
for(int dig = 0; dig <= 9; dig++){
for(int lst = 0; lst <= 9; lst++){
if(lst == 1 && dig == 3){
continue;
}
dp[LE][dig][i] += dp[LE][lst][i-1];
dp[LE][dig][i] %= MOD;
}
}
}
}
}
int ans = 0;
for(int i = 0; i <= 9; i++){
ans += dp[LE][i][str.size()-1] + dp[EQ][i][str.size()-1];
ans %= MOD;
}
return ans;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n >> q;
cin >> s;
s = "$"+s;
cout << countWays(s) << "\n";
while(q--){
cin >> t;
if(t == 1){
cin >> l >> r;
int len = r-l+1;
string str = s.substr(l, len);
cout << countWays("$"+str) << "\n";
}else{
cin >> pos >> val;
s[pos] = (val+'0');
}
}
return 0;
}
Compilation message
lucky.cpp: In function 'int countWays(std::string)':
lucky.cpp:14:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
14 | for(int i = 1; i < str.size(); i++){
| ~~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1116 KB |
Output is correct |
2 |
Correct |
1 ms |
1116 KB |
Output is correct |
3 |
Correct |
0 ms |
1116 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1116 KB |
Output is correct |
2 |
Correct |
1 ms |
1116 KB |
Output is correct |
3 |
Correct |
0 ms |
1116 KB |
Output is correct |
4 |
Correct |
1 ms |
1116 KB |
Output is correct |
5 |
Correct |
1 ms |
1116 KB |
Output is correct |
6 |
Correct |
1 ms |
1116 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1051 ms |
1552 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1051 ms |
1552 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1116 KB |
Output is correct |
2 |
Correct |
1 ms |
1116 KB |
Output is correct |
3 |
Correct |
0 ms |
1116 KB |
Output is correct |
4 |
Correct |
1 ms |
1116 KB |
Output is correct |
5 |
Correct |
1 ms |
1116 KB |
Output is correct |
6 |
Correct |
1 ms |
1116 KB |
Output is correct |
7 |
Execution timed out |
1051 ms |
1552 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1116 KB |
Output is correct |
2 |
Correct |
1 ms |
1116 KB |
Output is correct |
3 |
Correct |
0 ms |
1116 KB |
Output is correct |
4 |
Correct |
1 ms |
1116 KB |
Output is correct |
5 |
Correct |
1 ms |
1116 KB |
Output is correct |
6 |
Correct |
1 ms |
1116 KB |
Output is correct |
7 |
Execution timed out |
1051 ms |
1552 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |