MATCHS-TLE for all test cases except first test case

help

#1

Please help me to identify that where is my code going wrong…
https://www.codechef.com/viewsolution/24249257


#2

i have just some parts of your code ( only 2 lines) and got a AC
link : https://www.codechef.com/viewsolution/24267693
added these two lines:
1.for fast IO
ios_base::sync_with_stdio(false);
cin.tie(NULL);
2. you used q as long long int array of a large size i used vector instead of array so that i can save space.


#3

Why I am getting TLE if I can’t use vector in place of array?


#4

its interesting , there is no problem with using an array the problem lies using the following statement
int q[100000]={ }; or int q[100000]={0};
replace the statement with int q[100000];
you will get an AC.
I think that the array is set to a given value so it consumes time and results in a TLE , though I am not sure about this.


#6

Sorry, i was wrong. I tried to change your code. Moving the initialization of the variables and some conditions, and I got AC. https://www.codechef.com/viewsolution/24268075


#7

Ok, I found the cause of the problem with some tests.
https://www.codechef.com/viewsolution/24268129
https://www.codechef.com/viewsolution/24268139
The real problem is the inizialization of long long int q[100000] = {}; only by moving this line of code out of the while loop, we get AC.
@yashshahiiitdm


#8

Thanks, @andrew1234, @baby_stark
I got it…