MULTQ3 - Multiples of 3


There are N numbers a[0], a[1] ... a[N - 1]. Initially all are 0. You have to perform two types of operations :

  1. Increase the numbers between indices A and B (inclusive) by 1. This is represented by the command "0 A B"
  2. Answer how many numbers between indices A and B (inclusive) 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

Output:
4
1
0
2

Constraints

1 ≤ N ≤ 100000
1 ≤ Q ≤ 100000
0 ≤ A ≤ B ≤ N - 1


hide comments
shady51: 2018-01-10 12:04:32

Rectify the time limit for Java. I am using segment tree with lazy propagation with fast input/output, and still getting TLE, used the same approach in C++14 and got accepted.

Last edit: 2018-01-10 13:35:57
code_aim: 2017-09-29 16:43:28

Good one!!

vishakha14: 2017-08-17 15:08:56

Spoj is just too harsh for java users. TLE despite O(n + qlogn) + Fast I/O soln.

shubham_7616: 2017-06-14 18:00:23

Take size of array to be 10^6 and size of seg tree to be 4*(10^6).
Took 4*(10^5) and got 2 WAs.

sas1905: 2017-06-05 21:08:59

Segment+lazy..

lord_poseidon: 2017-05-29 11:44:31

AC in one go

akshayvenkat: 2017-05-25 06:47:45

Segment tree, lazy propogation , scanf+printf works just fine. Simple adhoc trick is the only optimization required.

rajeev_899: 2017-03-21 15:59:11

enjoyed solving this :) easy one AC in one go

shahzada: 2017-03-18 13:02:49

Internal Error->RE->AC (Easy though)

iam_ss: 2017-03-16 20:01:38

Easy question and a good practice for lazy propagation using Segmented Trees.


Added by:Varun Jalan
Date:2010-09-12
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: NODEJS OBJC VB.NET
Resource:own problem