the question of the program i have posted...

There are N numbers a[0],a[1]..a[N - 1]. Initally all are 0. You have to perform two types of operations :
1) Increase the numbers between indices A and B by 1. This is represented by the command "0 A B"
2) Answer how many numbers between indices A and B are divisible by 3. This is represented by the command "1 A B".
Input :
The first line contains two integers, N and Q. Each of the next Q lines are either of the form "0 A B" or "1 A B" as mentioned above.
Output :
Output 1 line for each of the queries of the form "1 A B" containing the required answer for the corresponding query.
Sample Input :
4 7
1 0 3
0 1 2
0 1 3
1 0 0
0 0 3
1 3 3
1 0 3

Sample Output :

Constraints :
1 <= N <= 100000
1 <= Q <= 100000
0 <= A <= B <= N - 1

it is giving run time error..earlier there is time limit exceeded error.
i want to know how should one approach with such a high range of input. time limit exceeded and run time error are most common errors i am facing with such hight input questions.
please explain...!!!

Recommended Answers

All 14 Replies

Please post the specific runtime error you're getting and also your code; we can't help if we don't know what you're doing.

this is my code....

using namespace std;
/*#define  N1 1000000
#define a[N1]
#define C[N1][3]*/
int a[1000000]={0};
int C[1000000][3];
int main()
long N,Q,A,B,count,A1,B1;
int i,j,k,i1,j1;
{ for(k=0;k<3;k++)
   { A=C[j][1];
/* for(o=0;o<=o1;o++)
     { cout<<"\n"<<output[o];}
return 0;

Please post the specific runtime error you're getting

And the error message is... ?

actually run time error was coming when i was declaring array 'a' inside main().
but now its showing time limit exceeded. i mean the site on which i am checking my solution showing "time limtit exceeded".
i know the array size is very big and using this big size in the loop basically the main reason of time limit exceeded.
there are many questions of such big range and i have same time problem.
how do i overcome this???

this code is giving me run time error now


int a[10000]={0};
using namespace std;
int main()
    int i,c,n,q,x,y,z;
    { q--;c=0;
        {  for(i=0;i<n;i++)
            { if(i>=y&&i<=z)
        { for(i=0;i<n;i++)

and the code i have posted earlier is giving time limit exceeded error.

above codes are my two logics to solve the problem.

this code is giving me run time error now

and the code i have posted earlier is giving time limit exceeded error.

above codes are my two logics to solve the problem.

I've finally had a chance to test your code--sorry for the delay!

Both versions of your code build, run, and work as expected for me... I don't see any runtime errors. Have you tried running them yourself, i.e., not through the site you're using to check your solution?

Again, posting the specific text of this mysterious runtime error would be a big help.

Are you able to run your program successfully on your computer?

int a[10000]={0};

Constraints :
1 <= N <= 100000

Most likely the fault is when N exceeds 10000 you've allocated.

yes..i m ..

In that case, I'm not sure what is wrong here... Looking at the site you're submitting to, I see from the comments that other people have been having trouble with apparently working code as well. There are quite a few "runtime error(SIGSEGV)" results--this sounds like something you should take up with whoever manages the site.

As for the "time limit exceeded" error, the limit is only one second... your original code had an array size of 1000000 (one million); that might have had something to do with it.

then how should i approach it ...i mean there are successful submissions of this problem too but i didnot understand their approach.
what will u do to make it successful.???

I'd stop using a site that a lot of people have errors on.

can anyone explain any of the successful C++ code posted there????

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.