#include <iostream>
#include <fstream>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <ctime>
#include <algorithm>
#include <sstream>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <cstdlib>
#include <cstdio>
#include <iterator>
#include <functional>
#include <unordered_set>
#include <unordered_map>
#include <stdio.h>
#include <bitset>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define ld long double
const ll maxn = 1e4 + 1, maxm = 80;
const ll mod = 1e9 + 7, inf = 1e9;
const ld eps = 1e-9;
int n, q;
string s;
int dig[maxn];
ll dp[maxn][10][2];
int calc(string x){
memset(dp, 0, sizeof(dp));
x = '#' + x;
int m = (int)x.size();
for (int j = 1; j < m; ++j){
dig[j] = x[j] - '0';
}
for (int i = 0; i <= dig[1]; ++i){
int ni = 1, nj = i, nk = (i == dig[1]);
dp[ni][nj][nk] = 1;
}
for (int i = 2; i < m; ++i){
for (int j = 0; j < 10; ++j){
for (int k = 0; k < 2; ++k){
if (dp[i - 1][j][k] > 0){
for (int ndig = 0; ndig < 10; ++ndig){
int ni = i, nj = ndig, nk = k;
if (k == 0){
if (!(ndig == 3 && j == 1)){
dp[ni][ndig][nk] = (dp[ni][ndig][nk] + dp[i - 1][j][k]) % mod;
}
}
else{
if (ndig < dig[i]){
nk = 0;
if (!(ndig == 3 && j == 1)){
dp[ni][ndig][nk] = (dp[ni][ndig][nk] + dp[i - 1][j][k]) % mod;
}
}
nk = k;
if (ndig == dig[i]){
if (!(ndig == 3 && j == 1)){
dp[ni][ndig][nk] = (dp[ni][ndig][nk] + dp[i - 1][j][k]) % mod;
}
}
}
}
}
}
}
}
ll ans = 0;
for (int i = 0; i <= 9; ++i){
for (int j = 0; j < 2; ++j){
ans = (ans + dp[m - 1][i][j]) % mod;
// cout << i << " " << j << " " << dp[m - 1][i][j] << '\n';
}
}
return ans;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> q;
cin >> s;
cout << calc(s) << '\n';
for (int i = 1; i <= q; ++i){
int type;
cin >> type;
if (type == 1){
int l, r;
cin >> l >> r;
string ss = "";
for (int j = l - 1; j <= r - 1; ++j){
ss += s[j];
}
cout << calc(ss) << '\n';
}
else{
int pos, dig;
cin >> pos >> dig;
s[pos - 1] = dig + '0';
}
}
}
Compilation message
lucky.cpp: In function 'int calc(std::string)':
lucky.cpp:60:37: warning: unused variable 'nj' [-Wunused-variable]
60 | int ni = i, nj = ndig, nk = k;
| ^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1876 KB |
Output is correct |
2 |
Correct |
1 ms |
1876 KB |
Output is correct |
3 |
Correct |
1 ms |
1876 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1876 KB |
Output is correct |
2 |
Correct |
1 ms |
1876 KB |
Output is correct |
3 |
Correct |
1 ms |
1876 KB |
Output is correct |
4 |
Correct |
2 ms |
1876 KB |
Output is correct |
5 |
Correct |
1 ms |
1876 KB |
Output is correct |
6 |
Correct |
1 ms |
1876 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1088 ms |
2016 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1088 ms |
2016 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1876 KB |
Output is correct |
2 |
Correct |
1 ms |
1876 KB |
Output is correct |
3 |
Correct |
1 ms |
1876 KB |
Output is correct |
4 |
Correct |
2 ms |
1876 KB |
Output is correct |
5 |
Correct |
1 ms |
1876 KB |
Output is correct |
6 |
Correct |
1 ms |
1876 KB |
Output is correct |
7 |
Execution timed out |
1088 ms |
2016 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1876 KB |
Output is correct |
2 |
Correct |
1 ms |
1876 KB |
Output is correct |
3 |
Correct |
1 ms |
1876 KB |
Output is correct |
4 |
Correct |
2 ms |
1876 KB |
Output is correct |
5 |
Correct |
1 ms |
1876 KB |
Output is correct |
6 |
Correct |
1 ms |
1876 KB |
Output is correct |
7 |
Execution timed out |
1088 ms |
2016 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |