Help in finding TLE

Правка en3, от cbertake, 2024-08-31 21:29:24

Can anyone tell me why is this giving TLE whereas the editorial code is basically the same. What's the issue here? My Code:

ll do_it(ll x){ ll ret=0; while(x>0){ ret+=x%10; x/=10; } return ret; } void solve(){ ll n,q;cin>>n>>q; ipar(a,n); setact;

for(int i=0;i<n;i++){
    if(a[i]>9)
        act.insert(i);
}
while(q--){
    ll c;cin>>c;
    if(c==1){
        ll l,r;cin>>l>>r;
        l--;r--;
        ll lst=l;
        while(!act.empty()){
            auto it=lower_bound(all(act),lst);///element which is >=l

            if(it==act.end() || *it>r)
                break;
            a[*it]=do_it(a[*it]);
            ll cur=*it;
            act.erase(it);
            if(a[cur]>9)///this reduces the size of act without need of cntop vector
                act.insert(cur);///a[cur] will alwasy eb less than original
            lst=cur+1;///it could happen that the processed elemtn enter at same place
            ///so increment lst to avoid double processing
        }
    }else {
        ll x;cin>>x;
        --x;
        cout<<a[x]<<"\n";
    }
}

}

Problem Link: https://codeforces.net/contest/1791/problem/F Editorial: https://codeforces.net/blog/entry/112282

Теги need help, tle

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en3 Английский cbertake 2024-08-31 21:29:24 0 (published)
en2 Английский cbertake 2024-08-31 21:29:03 6 Tiny change: 'My Code:\nll do_it' -> 'My Code:\n\n\n\nll do_it' (saved to drafts)
en1 Английский cbertake 2024-08-31 21:28:38 1400 Initial revision (published)