Can't figure out why my code is giving segmentation fault

This is question of lunch time https://www.codechef.com/LTIME73B/problems/BURARRAY
I have solved this question using segment trees but I am not able to figure out why it is giving segmentation fault for subtasks 2,3,4,5. Can someone help me.
My solution : https://www.codechef.com/viewsolution/25001739
Thanks for help in advance.

“N” can be upto 10^18 and you can’t define such large array.
In main function, you can define array upto 10^6;
and outside the main function you can define upto 10^7;

2 Likes

Thanks. Can you suggest an alternative?

first of all you need to change your logic to get 100 points, use map or hashing instead.

Thanks for helping. I’ll try another approach