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 Challenge 2013
    • May Cook-Off 2013
    • May Challenge 2013
  • DISCUSS
    • Forums
    • Blog
    • Wiki
    • Facebook
    • Twitter
  • COMMUNITY
    • Campus Chapters
    • Host your Contest
    • Go for Gold
    • All Educational Initiatives
  • HELP
    • Frequently Asked Questions
    • FAQ for problem setters
    • Problem Setting
    • Tutorials
    • Long Contest Ranks
    • Short Contest Ranks
    • Event Calendar
    • Top Contributors on Discuss
  • ABOUT
    • About CodeChef
    • Team CodeChef
    • Press Room
    • CodeChef Financials
    • CodeChef Sponsorships
    • CEO's Corner
    • Contact Us
    • About Directi
Home » Practice(medium) » Multiples of 3

Multiples of 3

Problem code: MULTQ3

  • Submit
  • 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
Tester: anshuman_singh
Editorial http://discuss.codechef.com/problems/MULTQ3
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, FORT, FS, GO, HASK, ICK, ICON, JAR, JAVA, JS, LISP clisp, LISP sbcl, LUA, NEM, NICE, NODEJS, 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.

its giving tle error . but in

phantom11 @ 31 Mar 2011 05:41 PM

its giving tle error . but in my pc its giving output in microsecs

smebody plz help

phantom11 @ 31 Mar 2011 05:42 PM

smebody plz help

#include<iostream>using

bhogal08547 @ 1 Apr 2011 04:48 AM
  • #include<iostream>
  • using namespace std;
  • int main()
  • {
  • int a[10000]={0},i,c,n,q,x,y,z;
  • cin>>n>>q;
  • while(q--)
  • { c=0;
  • cin>>x>>y>>z;
  • if(x==0)
  • { for(i=0;i<n;i++)
  • { if(i>=y&&i<=z)
  • a[i]++;
  • }
  • }
  • else
  • { for(i=0;i<n;i++)
  • if(i>=y&&i<=z)
  • if(a[i]%3==0)
  • c++;
  • cout<<c<<endl;
  • }
  • }
  • }

  • dont understand by i am getting runtime error..
    please any help me

    It seems to be working fine

    vimard @ 16 May 2011 02:41 PM

    It seems to be working fine mate.. I am not getting any runtime error

    Try this int

    vimard @ 16 May 2011 03:04 PM

    Try this

    int a[100000]={0},i,c,n,q,x,y,z;

    I think you won't get the runtime error

    Anyone help me..!!! This code

    abhinav_maini @ 3 Jul 2011 02:02 PM
    Anyone help me..!!! This code is giving Runtime error... import java.io.*; class multiples { public static void main(String argsp[])throws IOException { int i,j,n; BufferedReader input=new BufferedReader(new InputStreamReader(System.in)); n=Integer.parseInt(input.readLine()); PrintWriter pw = new PrintWriter(System.out, true); pw.print("Multiples of 3 are:"); for(i=0;i<=n;i++) { if(i%3==0) System.out.print(i+" "); } } }

    Is there anyway by which we

    cs5090240 @ 21 Sep 2011 12:58 AM
    Is there anyway by which we can know the running time of our program?

    No, there isn't. The judging

    shubh09 @ 21 Sep 2011 02:53 PM
    No, there isn't. The judging machines just stop executing the program once the time of execution exceeds the time limit for the problem. They don't wait for your program to return the result. Otherwise someone might submit a program containing an infinite loop, and the judging machine will have to wait forever for the result.

    Getting run time error even

    sauravprakash @ 1 Nov 2011 12:17 PM
    Getting run time error even if the code is running fine in my compiler.

    I'm submitting the code in

    voodoo_child @ 30 Nov 2011 03:42 PM
    I'm submitting the code in python.... it's giving correct output on the system .. here's it giving runtime error. Anyidea what the input method..... I'm using raw_input() ... shud i use any other input source?

    Fenwick tree?

    flareneos @ 30 Nov 2011 03:49 PM
    Fenwick tree?

    someone help me ...i can't

    balabarath @ 2 Dec 2011 07:31 PM
    someone help me ...i can't understand the problem...

    I really don't get it: The

    zunera @ 3 Dec 2011 12:41 AM
    I really don't get it: The time limit is only 1s but all solutions exceeds it!! Are all those algorithms really not as good or is the time limit not properly chosen?! I also exceed the time limit with my java solution :(

    @Admins: Please check this

    zunera @ 3 Dec 2011 02:57 AM
    @Admins: Please check this problem/testcases/..., I wasted a lot of time and I have no clue what for!

    @admin please could you check

    yanluis07 @ 12 Dec 2011 02:25 AM
    @admin please could you check what is wrong with my solution i don't find any problem

    The code is working fine on

    codephoenix @ 21 Feb 2012 04:45 PM
    The code is working fine on ma machine i have tried to optimise it but it still gives time limit exceeded

    this is my solution in python

    xonix_monty @ 23 Mar 2012 11:47 PM
    this is my solution in python 3.1 http://codepad.org/di1l2kM2 it is working fine on my system but Codechef always gives runtime error??

    Here I see time limit of 1

    karora @ 1 Apr 2012 01:40 AM
    Here I see time limit of 1 sec and see execution of accepted entries as 5 to 8 even 10 sec. May I know what is exact time limit for successful execution.

    How is this different from

    s1a3 @ 14 May 2012 11:46 AM
    How is this different from flipping coins problem? My solution was accepted ther but times out here. Any clue?

    ??? ideone is shwng 0.2

    anick_gemini @ 13 Jul 2012 07:40 PM
    ??? ideone is shwng 0.2 sec... still tle ???????

    #include int main() { long

    vaishum @ 4 Oct 2012 01:14 PM
    #include int main() { long int t,n,c; long int a[100001]; long int b,k,i,j,l; scanf("%ld",&n); scanf("%ld",&t); for(k=0;k

    @admin - can you suggest, how

    code_jazz @ 25 May 2013 06:23 AM
    @admin - can you suggest, how does lazy updation helps here in optimizing the solution rather than using conventional techniques? i see almost the same code copy pasted around and no no diff approach. Thnx (any links are most welcome)

    SUCCESSFUL SUBMISSIONS


    Fetching successful submissions

    HELP



    Program should read from standard input and write to standard output. After you submit a solution you can see your results by clicking on the [My Submissions] tab on the problem page. Below are the possible results:

     

    • Accepted Your program ran successfully and gave a correct answer. If there is a score for the problem, this will be displayed in parenthesis next to the checkmark.

    • Time Limit Exceeded Your program was compiled successfully, but it didn't stop before time limit. Try optimizing your approach.

    • Wrong Answer Your program compiled and ran succesfully but the output did not match the expected output.

    • Runtime Error Your code compiled and ran but encountered an error. The most common reasons are using too much memory or dividing by zero. For the specific error codes see the help section.

    • Compilation Error Your code was unable to compile. When you see this icon, click on it for more information.

    • If you are still having problems, see a sample solution here.
    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.