Submission #1341730

#TimeUsernameProblemLanguageResultExecution timeMemory
1341730inimadTrol (COCI19_trol)C++20
40 / 50
1094 ms436 KiB
#include<bits/stdc++.h>
using namespace std;

#define LL long long

int main() {
    ios::sync_with_stdio(0), cin.tie(0);
    
    int q;
    cin >> q;
    int a[11] = {};

    a[0] = 9;
    for(int i = 1; i < 9; i++){
        a[i] = i;
    }

    while(q--){
        LL l, r, m = 0, n = 0, ans = 0;
        cin >> l >> r;
        
        for(LL i = l; i <= r; i++){
            if(i % 9 == 1){
                m = i;
                break;
            }
            ans += a[i%9];
        }

        for(LL i = m; i <= r; i += 9){
            n = i;
            ans += 45;
        }

        ans -= 45;
        for(LL i = n; i <= r; i++) ans += a[i%9];

        if(m == 0){
            ans = 0;
            for(int i = l; i <= r; i++) ans += a[i%9];
        }

        cout << ans <<'\n';
    }    
}
#Verdict Execution timeMemoryGrader output
Fetching results...