In the last div 4 round I submitted a solution to this problem 1791F - Range Update Point Query which failed at the main tests and get TLE on test 66
I almost use the same idea mentioned in the editoiral and i have no idea why this code gives TLE
here is the submission : 191992725
can anybody help please
Ahmed_Allawati You have to clear the set s after each testcase.
This is not helping him
In
for(int i=l;i<=r;i++) { auto it=s.lower_bound(i); if(it==s.end()) break; if(*it>r) break; replace(i); }
you are replacing a[i], but you need to replace a[*it]. Because of this your solve's asymptothics if O(q*n*log), not (q*log). I propose you to do it like this:
int i = l; while(i <= r){ auto it = s.lower_bound(i); if(it==s.end()) break; if(*it>r) break; i = *it; replace(i, s, a); ++i; }
and you need to clear set too
void replace(int i, set &s, vector &a) { int c=a[i]; int ans=0; while(c > 0) { ans += c % 10; c /= 10; } a[i] = ans ; if(a[i]<10) { if(s.find(i) != s.end()) s.erase(i); } }
int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
}
this is your code after my debug, i swap string a to int a too, but i don't think, that it is important.
you can check this code on my submission #192255747
Yes i see .. thanks a lot
what a stupid mistake i made