Submission #302890

# Submission time Handle Problem Language Result Execution time Memory
302890 2020-09-19T11:35:25 Z 2fat2code Lucky Numbers (RMI19_lucky) C++17
100 / 100
64 ms 8724 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define all(a) (a).begin(), (a).end()
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define sz() size()
#define fr first
#define sc second
#define int long long
//#define mp make_pair
#define rc(s) return cout<<s,0
#define rcc(s) cout<<s,exit(0)

const int mod = 1e9 + 7;
const int nmax = 100005;

int n,q,dp[nmax][10],ans;
string s;

void add(int &a,int b){
    a = (a + b) % mod;
}

void calc(int digitleft,int pos,int prevdigit){
    for(int t=0;t<(int)(s[pos] - '0');t++){
        if(prevdigit == 1 && t == 3) continue;
        add(ans,dp[digitleft][t]);
    }
    if((int)(s[pos] - '0') == 3 && prevdigit == 1){
        return;
    }
    else if(digitleft == 1){
        add(ans,1LL);
        return;
    }
    else{
        calc(digitleft - 1, pos + 1, (int)(s[pos] - '0'));
    }
}

void precalc(){
    for(int i=0;i<=9;i++) dp[1][i] = 1;
    for(int i=2;i<=100000;i++){
        for(int j=0;j<=9;j++){
            for(int t=0;t<=9;t++){
                if(j == 1 && t == 3) continue;
                else{
                    add(dp[i][j],dp[i-1][t]);
                }
            }
        }
    }
}

int32_t main(){
    ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
    srand(chrono::steady_clock::now().time_since_epoch().count());
    cin >> n >> q >> s;
    precalc();
    ans = 0;
    calc(n,0,-1);
    cout << ans << '\n';
    for(int i=1;i<=q;i++){
        int type;
        cin >> type;
        if(type == 1){
            int l,r;
            cin >> l >> r;
            --l;
            --r;
            ans = 0;
            calc(r-l+1,l,-1);
            cout << ans << '\n';
        }
        else{
            int l;
            char r;
            cin >> l >> r;
            s[l - 1] = r;
        }
    }
}
# Verdict Execution time Memory Grader output
1 Correct 34 ms 8188 KB Output is correct
2 Correct 34 ms 8184 KB Output is correct
3 Correct 36 ms 8184 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 34 ms 8188 KB Output is correct
2 Correct 34 ms 8184 KB Output is correct
3 Correct 36 ms 8184 KB Output is correct
4 Correct 34 ms 8184 KB Output is correct
5 Correct 34 ms 8184 KB Output is correct
6 Correct 34 ms 8184 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 52 ms 8192 KB Output is correct
2 Correct 62 ms 8440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 52 ms 8192 KB Output is correct
2 Correct 62 ms 8440 KB Output is correct
3 Correct 57 ms 8620 KB Output is correct
4 Correct 58 ms 8572 KB Output is correct
5 Correct 62 ms 8724 KB Output is correct
6 Correct 64 ms 8696 KB Output is correct
7 Correct 64 ms 8696 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 34 ms 8188 KB Output is correct
2 Correct 34 ms 8184 KB Output is correct
3 Correct 36 ms 8184 KB Output is correct
4 Correct 34 ms 8184 KB Output is correct
5 Correct 34 ms 8184 KB Output is correct
6 Correct 34 ms 8184 KB Output is correct
7 Correct 52 ms 8192 KB Output is correct
8 Correct 62 ms 8440 KB Output is correct
9 Correct 44 ms 8312 KB Output is correct
10 Correct 49 ms 8412 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 34 ms 8188 KB Output is correct
2 Correct 34 ms 8184 KB Output is correct
3 Correct 36 ms 8184 KB Output is correct
4 Correct 34 ms 8184 KB Output is correct
5 Correct 34 ms 8184 KB Output is correct
6 Correct 34 ms 8184 KB Output is correct
7 Correct 52 ms 8192 KB Output is correct
8 Correct 62 ms 8440 KB Output is correct
9 Correct 57 ms 8620 KB Output is correct
10 Correct 58 ms 8572 KB Output is correct
11 Correct 62 ms 8724 KB Output is correct
12 Correct 64 ms 8696 KB Output is correct
13 Correct 64 ms 8696 KB Output is correct
14 Correct 44 ms 8312 KB Output is correct
15 Correct 49 ms 8412 KB Output is correct
16 Correct 48 ms 8572 KB Output is correct
17 Correct 47 ms 8588 KB Output is correct
18 Correct 50 ms 8696 KB Output is correct
19 Correct 53 ms 8696 KB Output is correct
20 Correct 51 ms 8660 KB Output is correct