CodeChef is a non-commercial competitive programming community
Login
Username (New User? Signup) Password (Forgot Password?)
Signup
Login or
Signup with
Connect
Note
  • Publicize your achievements on your Facebook Wall.
  • Challenge your friends or ask them for help.

Site Navigation

  • PRACTICE
    • Easy
    • Medium
    • Hard
    • Challenge
    • Peer
  • COMPETE
    • All Contests
    • June Long 2012
    • May Cook-Off
    • May Long 2012
  • DISCUSS
    • Forums
    • Blog
    • Wiki
    • Facebook
    • Twitter
  • COMMUNITY
    • CodeChef Meetups
    • Campus Chapters
    • Host your Contest
    • User Groups
    • CodeChef TechTalks
    • All Educational Initiatives
  • HELP
    • Frequently Asked Questions
    • FAQ for problem setters
    • Problem Setting
    • Tutorials
    • Long Contest Ranks
    • Short Contest Ranks
    • Event Calendar
  • ABOUT
    • About CodeChef
    • Team CodeChef
    • Press Room
    • CodeChef Financials
    • CodeChef Sponsorships
    • CEO's Corner
    • Contact Us
    • About Directi
Home » Compete » September 2010 Challenge » Multiples of 3

Multiples of 3

Problem code: MULTQ3

  • All Submissions

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


  • Submit

Comments

  • Login or Register to post a comment.

Could you please increase

pdwd @ 1 Sep 2010 04:07 PM

Could you please increase time limit? 1 s is too little for optimal solution to pass.

M not getting the Submit a

Rounak Tibrewal @ 1 Sep 2010 05:06 PM

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

pdwd @ 1 Sep 2010 05:11 PM

Ok now I don't want increasing time limit :P

Do v have

urbaddy @ 1 Sep 2010 06:17 PM

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

pdwd @ 1 Sep 2010 06:36 PM

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

anshuavi @ 1 Sep 2010 08:04 PM

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

abhishek890 @ 1 Sep 2010 08:40 PM

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

webspiral @ 1 Sep 2010 09:23 PM

Can someone please explain me how they are getting the output for the given input ?

This is my first submit here,

avnv @ 1 Sep 2010 09:41 PM

This is my first submit here, can anyone tell me for how many inputs we have to code?

@abhishek : 1 0 3 , here 0

avnv @ 1 Sep 2010 09:52 PM

@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

iman_movahedi @ 1 Sep 2010 09:56 PM

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

iman_movahedi @ 1 Sep 2010 09:56 PM

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

iman_movahedi @ 1 Sep 2010 09:56 PM

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

iman_movahedi @ 1 Sep 2010 09:58 PM

@admin : are you here ?

 

why my solution(iman_movahedi) is time limitd ?

and also the first input 4

avnv @ 1 Sep 2010 10:08 PM

and also the first input 4 and 7 are no of queries and value of n

@iman TLE(Time Limit exceded)

gauravgaba @ 1 Sep 2010 10:26 PM

@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

admin @ 1 Sep 2010 11:01 PM

@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

wiwbiz @ 2 Sep 2010 01:58 AM

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"

liubiaoyong @ 2 Sep 2010 08:52 AM

could I know how much "1 A B" in the input ?

@Avinav, Thanks Avinav. But

webspiral @ 2 Sep 2010 12:48 PM

@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

talreja_rajesh @ 2 Sep 2010 02:27 PM

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

triplem @ 2 Sep 2010 02:28 PM

The numbers are initially 0,0,0,0, not 0,1,2,3.

I provide input to programe

suhas01 @ 2 Sep 2010 02:35 PM

I provide input to programe  in input.txt.

Is this right way....

If no, then which is correcte way...

Thanks

FAQ

triplem @ 2 Sep 2010 04:42 PM

FAQ

Is it acceptable to print

wiwbiz @ 3 Sep 2010 12:24 AM

Is it acceptable to print output after every '1 x x' input ? Please answer yes or no.

@Lucky - you said you read

triplem @ 3 Sep 2010 04:42 AM

@Lucky - you said you read the FAQ.. try again (second bullet point in the first question).

can any body tell me what

kirtan @ 3 Sep 2010 08:04 PM

can any body tell me what does 4 stands for in 4 7 ?


i think 7 is stand for total number of lines we input but what about 4 ?

@Kirtan Please refrain from

anshuman_singh @ 3 Sep 2010 09:08 PM

@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

gauravgaba @ 3 Sep 2010 10:32 PM

@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

santhosh.codechef @ 3 Sep 2010 11:45 PM

@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

shadow @ 5 Sep 2010 01:02 AM

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

admin @ 5 Sep 2010 11:07 AM

@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

cegprakash @ 5 Sep 2010 07:34 PM

can anyone plz tell is there any short ways to find whether modulus of 3 =0?

any clues for how to reduce

cegprakash @ 5 Sep 2010 07:44 PM

any clues for how to reduce the time limit?

Can I use Files at all in my

nitishgarg91 @ 5 Sep 2010 08:03 PM

Can I use Files at all in my program? Does Codechef supports Files?

I am using file handling in

ashima @ 5 Sep 2010 09:59 PM

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

triplem @ 6 Sep 2010 02:36 AM

FAQ

what are ways to reduce time

mehul_mittal @ 6 Sep 2010 08:35 PM

what are ways to reduce time limit?

To all those asking for ways

shubh09 @ 7 Sep 2010 11:54 PM

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

jaydeepfifadra @ 8 Sep 2010 06:21 PM

Is there anybody who can solve this problem within given time using JAVA?

@Jaydeep Fifadra I just

spooky @ 9 Sep 2010 03:14 PM

@Jaydeep Fifadra

I just did...

@admin-i am not getting the

mayankj08 @ 9 Sep 2010 04:51 PM

@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

arjunhack @ 9 Sep 2010 05:37 PM

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.

arjunhack @ 9 Sep 2010 06:03 PM

Sorry guys i understood now.

code chef compiler is

moniv9 @ 10 Sep 2010 02:32 AM

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

vish @ 10 Sep 2010 02:39 AM

@Mohit

how is your TLE linked with CC's compiler???

They are having same compiler as we..

@admin my program is getting

sunny816.iitr @ 10 Sep 2010 10:28 PM

@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

peeyushagrawal @ 11 Sep 2010 04:11 PM

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

peeyushagrawal @ 11 Sep 2010 04:19 PM

@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.

triplem @ 11 Sep 2010 04:38 PM

@peeyush - read the FAQ.

Can someone please give an

andipandi @ 14 Sep 2010 12:29 PM

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

naveenraiit @ 28 Sep 2010 05:48 PM

#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

triplem @ 29 Sep 2010 06:32 AM

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.

SUCCESSFUL SUBMISSIONS FOR THIS PROBLEM:

Programming Competition Fetching successful submissions
Directi Go for Gold
CodeChef is a global programming communityCodeChef hosts online programming competitions
CodeChef is a non-commercial competitive programming community
  • About CodeChef
  • About Directi
  • CEO's Corner
  • C-Programming
  • Programming Languages
  • Contact Us
© 2009 Directi Group. All Rights Reserved. CodeChef uses SPOJ © by Sphere Research Labs
In order to report copyright violations of any kind, send in an email to copyright@codechef.com
CodeChef a product of Directi
The time now is:
CodeChef - A Platform for Aspiring Programmers

CodeChef was created as a platform to help programmers make it big in the world of algorithms, computer programming and programming contests. At CodeChef we work hard to revive the geek in you by hosting a programming contest at the start of the month and another smaller programming challenge in the middle of the month. We also aim to have training sessions and discussions related to algorithms, binary search, technicalities like array size and the likes. Apart from providing a platform for programming competitions, CodeChef also has various algorithm tutorials and forum discussions to help those who are new to the world of computer programming.

Practice Section - A Place to hone your 'Computer Programming Skills'

Try your hand at one of our many practice problems and submit your solution in a language of your choice. Our programming contest judge accepts solutions in over 35+ programming languages. Preparing for coding contests were never this much fun! Receive points, and move up through the CodeChef ranks. Use our practice section to better prepare yourself for the multiple programming challenges that take place through-out the month on CodeChef.

Compete - Monthly Programming Contests and Cook-offs

Here is where you can show off your computer programming skills. Take part in our 10 day long monthly coding contest and the shorter format Cook-off coding contest. Put yourself up for recognition and win great prizes. Our programming contests have prizes worth up to Rs.20,000 and $700lots more CodeChef goodies up for grabs.

Discuss

Are you new to computer programming? Do you need help with algorithms? Then be a part of CodeChef's Forums and interact with all our programmers - they love helping out other programmers and sharing their ideas. Have discussions around binary search, array size, branch-and-bound, Dijkstra's algorithm, Encryption algorithm and more by visiting the CodeChef Forums and Wiki section.

CodeChef Community

As part of our Educational initiative, we give institutes the opportunity to associate with CodeChef in the form of Campus Chapters. Hosting online programming competitions is not the only feature on CodeChef. You can also host a coding contest for your institute on CodeChef, organize an algorithm event and be a guest author on our blog.

Go For Gold

The Go for Gold Initiative was launched about a year after CodeChef was incepted, to help prepare Indian students for the ACM ICPC World Finals competition. In the run up to the ACM ICPC competition, the Go for Gold initiative uses CodeChef as a platform to train students for the ACM ICPC competition via multiple warm up contests. As an added incentive the Go for Gold initiative is also offering over Rs.8 lacs to the Indian team that beats the 29th position at the ACM ICPC world finals. Find out more about the Go for Gold and the ACM ICPC competition here.

Domain Name Registration, Web hosting, and Website Design provided by BigRock.com