DCEPC11I - Impossible Boss
Vaibhav Sir and Saikat Sir, after completing their graduation, got a job together at a store.
Their boss at the store was Sidharth Sir, who was very strict and did not want anyone to have fun at the job. He gave Vaibhav and Saikat sir a very boring job of stacking columns of boxes in a row of size N.
To make it a little interesting, both of them decided that whenever they need to add more boxes, they will choose st and en, such that 1<=st<=en<=N, and place 1 box in column st, 2 boxes in column st+1, … and (en-st+1) boxes in column en.
When Sidharth sir saw this, he decided to have some fun of his own, and asked them to count the number of boxes in all columns from st to en, and tell him the result. Now Vaibhav and Saikat sir have come to you for help to answer the queries of their boss, as they do not want to lose their jobs.
The first line contains N, the number of columns and Q, the number of queries.
The next Q lines can be of the following form –
1) 0 st en, meaning Vaibhav and Saikat sir add boxes to the columns from st to en as described above.
2) 1 st en, meaning Sidharth sir asks them to count the number of boxes in all columns from st to en.
For all queries of type 2, output a line containing the answer to the query.
Input: 5 6
0 2 4
1 1 5
0 1 5
0 3 5
1 1 5
1 3 5 Output: 6
Easy Segment tree!! :)
BIT Nailed It :)
For some reason take n as long long. That's all I changed in my code and got AC from previous int n.
Nice Problem to solve.. :-)
Why language restrictions?
|Added by:||dce coders|
|Cluster:||Cube (Intel G860)|
|Languages:||All except: ADA95 ASM32 ASM64 GAWK BASH BF CLPS CLOJURE LISP clisp LISP sbcl D ERL FSHARP FORTRAN GO ICON ICK JS-RHINO LUA NEM NICE NODEJS OCAML PERL PERL6 PHP PIKE PRLG-swi RUBY SCALA SCM guile SCM qobi SED ST TCL WHITESPACE|