Multiples of 3Problem code: MULTQ3 |
All submissions for this problem are available.
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 : 4 1 0 2
Constraints : 1 <= N <= 100000 1 <= Q <= 100000 0 <= A <= B <= N - 1
| Author: | syco |
| Date Added: | 11-04-2010 |
| Time Limit: | 1 sec |
| Source Limit: | 50000 Bytes |
| Languages: | ADA, ASM, BASH, BF, C, C99 strict, CAML, CLOJ, CLPS, CPP 4.0.0-8, CPP 4.3.2, CS2, D, ERL, F#, FORT, GO, HASK, ICK, ICON, JAR, JAVA, JS, LISP clisp, LISP sbcl, LUA, NEM, NICE, PAS fpc, PAS gpc, PERL, PERL6, PHP, PIKE, PRLG, PYTH, PYTH 3.1.2, RUBY, SCALA, SCM guile, SCM qobi, ST, TEXT, WSPC |
Comments

Fetching successful submissions

Could you please increase
Could you please increase time limit? 1 s is too little for optimal solution to pass.
M not getting the Submit a
M not getting the Submit a Solution page for any of the problems.So m not able to submit. please see to it.
Ok now I don't want
Ok now I don't want increasing time limit :P
Do v have
Do v have to increment numbers at A and B as well.
Can some one explain the sample output??
1 0 3 -> 4 numbers divisible
1 0 3 -> 4 numbers divisible by 3 t[0] = .. = t[3] = 0
0 1 2 -> t[1] = t[2] = 1
0 1 3 -> t[1] = t[2] = 2, t[3] = 1 and so on
My program shows correct
My program shows correct output,as far as I have checked.So why it is showing as wrong answer?
is there a way how to check
is there a way how to check what time my program took...its giving the limit has exceeded..does this mean my answer is correct but not within time??
Can someone please explain me
Can someone please explain me how they are getting the output for the given input ?
This is my first submit here,
This is my first submit here, can anyone tell me for how many inputs we have to code?
@abhishek : 1 0 3 , here 0
@abhishek : 1 0 3 , here 0 and 3 are A ann B.. and the first integer(here 1) is the type of task you have to perform.. so you have to find all the numbers divisible by 3 from a[0] to a[3].. there are 4 .. also no. of outputs are 4 because there are four inputs with (1,A,B) type..
is there a way how to check
is there a way how to check what time my program took...its giving the limit has exceeded..does this mean my answer is correct but not within time??
is there a way how to check
is there a way how to check what time my program took...its giving the limit has exceeded..does this mean my answer is correct but not within time??
is there a way how to check
is there a way how to check what time my program took...its giving the limit has exceeded..does this mean my answer is correct but not within time??
@admin : are you here ? why
@admin : are you here ?
why my solution(iman_movahedi) is time limitd ?
and also the first input 4
and also the first input 4 and 7 are no of queries and value of n
@iman TLE(Time Limit exceded)
@iman
TLE(Time Limit exceded) means ur program didnt stop within the specified time limit therfore nothing can be said about the correctness of ur program....
@Rounal: Hope your problem is
@Rounal: Hope your problem is fixed now.
Guys: Please refer or FAQ for doubts on TLE, Wrong Answer, Input Output Format and other such cases.
Just out of curiousity. is it
Just out of curiousity. is it acceptable to show output after each '1 x x' input ? I have read FAQ. Did any accepted solution followed this routine ?
could I know how much "1 A B"
could I know how much "1 A B" in the input ?
@Avinav, Thanks Avinav. But
@Avinav, Thanks Avinav. But how are they getting getting 4 for 1 0 3. We need to test 0,1,2,3 if they are divisible by 3. So we should get 2 right, 0 and 3.
My code is compiling and
My code is compiling and giving correct output and in your site it is giving error no main method found an dit has the main method...Do check my submission pls..
The numbers are initially
The numbers are initially 0,0,0,0, not 0,1,2,3.
I provide input to programe
I provide input to programe in input.txt.
Is this right way....
If no, then which is correcte way...
Thanks
FAQ
FAQ
Is it acceptable to print
Is it acceptable to print output after every '1 x x' input ? Please answer yes or no.
@Lucky - you said you read
@Lucky - you said you read the FAQ.. try again (second bullet point in the first question).
can any body tell me what
can any body tell me what does 4 stands for in 4 7 ?
@Kirtan Please refrain from
@Kirtan Please refrain from using big fonts. 4 stands for the size of the array. Kindly read the question carefully.
@VIJAYENDRA This is a contest
@VIJAYENDRA
This is a contest u can't ask for this sort of help.
Rule No 1 of the contest
" Please do not discuss strategy, suggestions or tips in the comments during a live contest. Posting questions clarifying the problem statement is ok "
@Vijayendra Nigam check with
@Vijayendra Nigam
check with input given in the program, your program given invalid output...
don't print anything other then what is mentioned(asked) in the output..
and
its contest. so we do discuss after 11th sept
best of luck
Hello Admin My program gives
Hello Admin
My program gives right answer for worst cases also but here it is exceeding time limit please look for once.
http://www.codechef.com/viewsolution/323422
Thanks
Gunjan Sharma
@Gunjan: Such help will not
@Gunjan: Such help will not be provided. Wait for the contest to get over to see editorials and other's solutions to become visible so that you can compare the logic of your programs with others and also the complexity to find out where your solution can improve.
can anyone plz tell is there
can anyone plz tell is there any short ways to find whether modulus of 3 =0?
any clues for how to reduce
any clues for how to reduce the time limit?
Can I use Files at all in my
Can I use Files at all in my program? Does Codechef supports Files?
I am using file handling in
I am using file handling in my program and it is showing run time error...while it is working fine with me.
I have read input from file...can somebody help me...
FAQ
FAQ
what are ways to reduce time
what are ways to reduce time limit?
To all those asking for ways
To all those asking for ways to reduce the running time of your program:
That is what the problem is all about. If you are told this, the problem won't be a challenge problem anymore. There is nothing to the problem except optimizing your solution to be more time efficient. If you can't think of it, wait for the contest to get over. Editorials for all the problems and all submitted solutions will be made available then.
Is there anybody who can
Is there anybody who can solve this problem within given time using JAVA?
@Jaydeep Fifadra I just
@Jaydeep Fifadra
I just did...
@admin-i am not getting the
@admin-i am not getting the complier and editor will you please help.also m using dev-c++ but it does not allows iostream it allows a=iostream.h
I am a newcomer to this
I am a newcomer to this website and this is the first problem i am trying to solve. here they ask us to give a default value of 0 to all the array members. and we fix the array length to 4 in sample output. but when they input 1 0 3 it means they ask the program to print the total no of numbers that are divisible by 3 between the indices 0 and 3. As all are holding a default value of 0 we should get an answer 0. but how it is possible to get 4?
Sorry guys i understood now.
Sorry guys i understood now.
code chef compiler is
code chef compiler is stupid...i m doing this program with only 2 loops..getting same output as given samples...n tried a lot more values all working fine...but here it always shows time limit exceeded...this is really dissappointing
@Mohit how is your TLE linked
@Mohit
how is your TLE linked with CC's compiler???
They are having same compiler as we..
@admin my program is getting
@admin
my program is getting Runtime error(SIGABRT) and about that FAQ says(SIGABRT errors are caused by your program aborting due to a fatal error)
what does it exactly mean by FATAL error
hi admin, now when the
hi admin,
now when the contest has been ended, can i submit my solution (i know i won't be rewared points for that) ??/
@admin please make provision
@admin
please make provision for submitting problems after contest ends ( don't give any mark, but to check that whether it's running correctly now)
@peeyush - read the FAQ.
@peeyush - read the FAQ.
Can someone please give an
Can someone please give an idea of what data structures/ideas are behind all the winning solutions?
I created some but never came close to the running time of the best ones here.
Also, the solution is so unknown to me, i cannot make much out of the code..
#include<iostream> using
#include<iostream>
using namespace std;
int main()
{
int N=0,i=0,j=0,k=0,op=0,a=0,b=0,c=0,l=0,count=0;
cin>>N;
int arr[N];
for(i=0;i<N;i++)
arr[i]=0;
cin>>op;
for(i=0;i<op;i++)
{
cin>>a>>b>>c;
if(a==0)
{
for(j=b;j<=c;j++)
arr[j]=arr[j]+1;
}
if(a==1)
{
count=0;
for(k=b;k<=c;k++)
{if(arr[k]%3==0)
count++; }
cout<<count<<endl;
}
}
//cin>>a;
return 0;
}
/*whether s code is right or wrong I want to know */
You can submit your code at
You can submit your code at the same problem in the practice section; http://www.codechef.com/problems/MULTQ3/
It definitely will not be correct, as it doesn't have a chance of running large inputs inside the time limit.