Here is my AC submission to the problem
My doubt is this :Why is my code NOT giving MEMORY LIMIT EXCEEDED?
Looking at the constraints ,my code should be using 4*(1e3)*(N) bits of memory.(where N<=1e5).
but the memory limit allowed is only 8*(1e4)*8 bits.