Funny Marbles

All submissions for this problem are available.
Read problems statements in Mandarin Chinese and Russian.
Storyline
Lira loves marbles very much and she especially loves to play with them with her school friends.
Today, Lira is very excited, as her mom said she would give her and her friends some new marbles for her to play with. She immediately requested her mom to give her the new marbles, but, her mom had some tricks kept up her sleeve:
Mom: "Not so fast, young girl!! These won't come for free! If you want to keep playing with them, you must prove you deserve them!!"
Lira: *moans* "Alright, mom, what do I have to do now?"
(Yes, Lira's mom can be quite annoying)
Mom: "Well, you can assume that I have an array A of size N , where N is the total number of students I will give marbles to, and A[i] is the number of marbles each student initially has."
Lira: *smiles slightly* "So you're feeling generous hum?"
Mom: "Well, not too generous... imagine I wanted to give more marbles to some of your school friends who do well on their exams, or, on the other hand take away some marbles from the greedier friends."
Lira: "Mom, c'mon that's too easy!!"
Mom: "Alright, so given a group of students, starting on student i and ending on student j, I want to know how many marbles they have together!"
Well, it turns out that Lira actually did solve this problem and she did it very efficiently!!
It's now your turn to solve the problem that Lira already did in a brilliant way!
Formal description:
Lira is given array A, which contains elements between 1000 and 2000.
Three types of queries can be performed on this array: add a given value to a single element on it, subtract a given value from a single element on it and find the sum of the values between indexes i and j, i.e. A[i]+...+A[j]. Check input and example section for details.
Input
The first line of the input contains two integers: N and Q, denoting respectively, the number of students that there are present to receive the marbles as a gift and the number of actions Lira's mom will perform.
These actions can be of three different types:
Output
The output should contain as many lines as the number of queries S and it should contain the answer for each query on a separate line
Constraints
 2 ≤ N ≤ 1000000
 3 ≤ Q ≤ 50000
 The array is 0indexed.
 1000 ≤ A[i] ≤ 2000
 A student can never have a negative value of marbles. (i.e. there's no data which can cause a student to have a negative value of marbles)
 0 ≤ i, j ≤ N1, and i ≤ j for the sum query
 At any given time, it is assured that the maximum number of marbles each student can have (num_marbles) never exceeds the size of the int data type.
Example
Input:5 3 1000 1002 1003 1004 1005 S 0 2 G 0 3 S 0 2 Output: 3005 3008
Author:  kuruma 
Tester:  gerald 
Editorial  http://discuss.codechef.com/problems/MARBLEGF 
Tags  dec13 easy kuruma 
Date Added:  4112013 
Time Limit:  1 sec 
Source Limit:  50000 Bytes 
Languages:  ADA, ASM, BASH, BF, C, C99 strict, CAML, CLOJ, CLPS, CPP 4.3.2, CPP 4.9.2, CPP14, CS2, D, ERL, FORT, FS, GO, HASK, ICK, ICON, JAVA, JS, LISP clisp, LISP sbcl, LUA, NEM, NICE, NODEJS, PAS fpc, PAS gpc, PERL, PERL6, PHP, PIKE, PRLG, PYTH, PYTH 3.4, RUBY, SCALA, SCM guile, SCM qobi, ST, TCL, TEXT, WSPC 
Comments
 Please login at the top to post a comment.
SUCCESSFUL SUBMISSIONS
Fetching successful submissions
The Input Specification does
" and A[i] is the number of
So, the sample test
@kuruma I am a big fan of
@ervin90, this will be fixed
The output statement : "The
@bcinc, Queries of the form
i am getting correct answers
@bruno_adm constraints means
Can anyone help? I am
lookout for character input
Could you give me a test,
The same program when i use
Still getting WA with cin and
Please check test case
10 lakh friends are not
No matter what i do, still
why getting TLE tried cin and
got A.C... phew!!
I really think is a problem
Had to switch from
@inseder thanks buddy i owe
TLE :(
Changed scanf to fast input
@ashish1610: What did u use
Is there a space between 'S'
same program in c++ got
For sure, there are different
for scanning....'S', 'G' and
will i and j be same for all
@odule, I can assure you that
@bi229, no.
TLE :(
TLE :(
tricky problem
Statement says int is enough
getting an nzec , test case
WA because of scanf :(
TLE not again..............
there is no description about
CAN ANYONE HELP ME .... I M
@bruno_adm: some test have
TLE.. TLE... can anyone
TLE!!!
Run time error :(
@code_overlord and @rahugur,
@aakashanuj, you should watch
dont know why in the hell i
Can someone tell me how to
@jujubi, you can :)
Getting NZEC in reading input
@ninetynine +1 for your
basics of scanf is also being
Getting NZEC for my python
Those who are thinking that
How to get the input in the
getting NZEC with python :(
how to read 10^6 input values
got two WA due to long long
getting NZEC with python
@bruno_adm Are yo sure there
@bruno_adm There are some
I think the problem is that
@admin how to store 10^6
any advice if I get TLE?
@admin Just to mention a few
@saimadan Make the array
cool_techie how ??
@admin  i just cant figure
Getting nzec with pyhton..
Getting TLE first,..now
@krobin_93 may be you don't
could anyone help in getting
what d hell is wrong with
could someone please suggest
I am getting SIGSEGV after
23 attempts to this question
Is it necessary that the
getting TLE after lot of
krobin_93 Same here.. @ksumit
To Admin, I feel something
of course other than fast IO
any suggestions for tle in
getting tle,is it for io or
got AC after changing scanf
@admin Getting WA but I am
Finally got AC. After many
The statement is some
Something is so seriously
@iovesnov : can you please
all those getting wrong
for c++ users, use "long
can any1 tell me about its
@aniketgoyal, 10^8 will not
@all, regarding mistakes,
@bruno_adm...my C++ solution
@pale_rider, the partial test
@bruno_adm, oh tanx. I didn't
could anyone please help.. I
Getting TLE @all who got
Same for me also! Changed
NZEC for Python! Could anyone
This fixed the code for me
Gives TLE with C using
what are these fast i/o
@san_disk no need for fast
@all, you can get AC using
my submission is always
@kuruma : This problem made
still getting nzec in java
@admin i tried on many test
this problem really sucks
TLE TLE TLE..... tried
@krobin_93 check running time
"At any given time, it is
@irajvardhan Yes,
Finally got accepted :) .
I really hope the editorial
irajvardhan: The constraints
@irajvardhan, exactly what
changing int to long long,
tricky one, AC :) ,,
Although I've got an AC in
complexity of the problem
can anyone tell me how to get
Finally got AC after tons of
after so many wa so many tle
Finally AC!! \m/
getting wa without using long
@aviraltrivedi This simple
@admin.........test as many
@admin......m struk at sol
small_devil: If you're
Can someone say the running
@admin........but the sol is
small_devil: my solution for
@ashish1610 can u tell how
TLE!!! somebody please post a
first accepted N and Q and
Got a green tick against it,
answer not always fits in int
Getting SIGSEGV. took long
NZEC in python with multiple
nice Q got Ac after 4 tle
Does the O(Q^2) solution
@mbaros, well, given the TL
taken long long int but still
now getting tle ! can
Does this easy problem seem
thanq @codefor6768 .. ur
No accepted python
TLE
bruno_adm Can you please look
getting TLE .... again and
bruno_adm
TLE in both C++ and JAVA!! :(
@aj95 Try searching out for a
@damn_me, look out for global
please check my solution:
please check my solution:
@all : For all those getting
huh.. tired of this tle ....
@bruno_adm I m gettin a NZEC
TLE :(
@parispar thanks. used long
@carpedium Yes it can be
Can Some one help What is
TLE:)..why i am getting
The condition
@all:phew...solved
@admin: i would like to know
@bruno_adm getting a WA...
admin plz rejudge the
admin plz rejudge the
bruno_adm http://www.codechef
@admin: Please have a look at
nice question ...for guys
@johri21:I have used long
@ramin7, DO NOT encourage
tried linked list and
getting NZEC but if i put a
finally got it accepted
JAVA: Works fine for test
Seriously? Why can't you all
Weird! When taking character
Not a single AC in