TLE on Minion and Range solution

For the problem Minion AND Range Problem Code: MINIAND my solution is giving TLE whereas it should pass the test cases in the given time limit.

My solution

Logic Used :

Used a prefix array(named - eo) which stores the no of even numbers encountered till i’th position in the given array

During query, checked whether the given range l-r contains any even number or not (lookup in eo by doing eo[r-1] - eo[l-1] >0 and also checked l’th element eo[l-1] - eo[l-2]>0).

for my approach the time complexity should be O(t(n+q)) which suffice enough to pass all condition within the given time limit, but still getting TLE.

It might be the time taken to read in input, or it could be the out-of-bounds access occuring with e.g. the testcase:

1                   
5
1 1 1 1 1
1
1 2

messing things up.

1 Like

Just added one line (the syncing one) solved it. Thanks for the help, also thanks for pointing out the accessing inaccessible memory address.

1 Like