Xsquare And Two Arrays
Practice
3.6 (89 votes)
Approved
Basic programming
Dynamic programming
Easy
Implementation
Open
Problem
58% Success 22109 Attempts 20 Points 5s Time Limit 256MB Memory 1024 KB Max Code

Xsquare loves to play with arrays a lot. Today, he has two arrays named as A and B. Each array consists of N positive integers.

Xsquare has decided to fulfill following types of queries over his array A and array B.

  • 1 L R : Print the value of AL + BL+1 + AL+2 + BL+3 + ... upto Rth term.
  • 2 L R : Print the value of BL + AL+1 + BL+2 + AL+3 + ... upto Rth term.

Input

First line of input contains two space separated integers N and Q denoting the size of arrays ( A , B ) and number of queries respectively. Next N lines of input contains N space separated integers denoting array A. Next line of input contains N space separated integers denoting array B. Next Q lines of input contains Q queries (one per line). Each query has one of the above mentioned types.

Output

Output consists of Q lines, each containing answer to the corresponding query.

Constraints

  • 1 ≤ N,Q ≤ 105
  • 1 ≤ Ai,Bi ≤ 109
  • 1 ≤ L,R ≤ N

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:20
29 votes
Tags:
Ad-HocApprovedEasyImplementationOpen
Points:20
8 votes
Tags:
AlgorithmsDynamic ProgrammingDynamic programmingEasyHash Maps
Points:20
16 votes
Tags:
AlgorithmsBrute-force searchDynamic ProgrammingEasyImplementation