Palindrome?
InterviewTime limit0.5sMemory limit256 MB
Answer up to a million queries asking whether a given range of the number sequence is a palindrome.
- Level
Medium4 of 10
- Topics
- Dynamic programming, Intervals
- Solved
- No attempts yet
Problem
Myeongwoo and Hongjun play a palindrome game.
Hongjun first writes natural numbers on a board. He then asks Myeongwoo questions.
Each question is a pair of integers and (). It asks whether the numbers from the -th to the -th on the board form a palindrome, and Myeongwoo must answer yes or no. A sequence is a palindrome when reading it forward gives the same result as reading it backward.
Suppose Hongjun writes 1, 2, 1, 3, 1, 2, 1 on the board.
- With , the numbers are 1, 2, 1, which is a palindrome.
- With , the numbers are 2, 1, 3, 1, which is not a palindrome.
- With , the number is 1, which is a palindrome.
- With , the numbers are 1, 2, 1, which is a palindrome.
Given the numbers and the questions, write a program that produces all of Myeongwoo's answers.
Input
The first line contains the size of the sequence ().
The second line contains the numbers Hongjun wrote on the board, in order. Each number is a natural number no greater than 100,000.
The third line contains the number of questions ().
Each of the next lines contains one question, given as and .
Output
Print Myeongwoo's answers on lines, in the order the questions are given. Print 1 if the range is a palindrome and 0 if it is not.