PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#PS0000128. Kiểm tra đoạn toàn hợp lệ (All Valid Range)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Kiểm tra đoạn toàn hợp lệ (All Valid Range)

All Valid Range

Source: Phước Hưng OJ

Version: Phuoc Hung OJ Extended

Problem Statement

Given a binary array b1,…,bnb_1,\ldots,b_n, call an entry valid if it equals 1 and invalid if it equals 0. For each inclusive interval [l,r][l,r], determine whether every entry in it is valid. The array does not change.

Input

The first line contains n,qn,q, the array length and query count.

The second line contains nn integers b1,…,bnb_1,\ldots,b_n.

Each of the next qq lines contains integers l,rl,r.

Output

Print qq lines: YES if every entry in the queried interval equals 1, otherwise NO.

Subtasks

  • Subtask 1 (30 points): 1≤n≤1001\le n\le100; 1≤q≤1001\le q\le100; 1≤l≤r≤n1\le l\le r\le n for each query; bi∈{0,1}b_i\in\{0,1\} for every 1≤i≤n1\le i\le n.
  • Subtask 2 (30 points): 1≤n≤2000001\le n\le200000; 1≤q≤2000001\le q\le200000; 1≤l≤r≤n1\le l\le r\le n for each query; bi=1b_i=1 for every 1≤i≤n1\le i\le n.
  • Subtask 3 (40 points): 1≤n≤2000001\le n\le200000; 1≤q≤2000001\le q\le200000; 1≤l≤r≤n1\le l\le r\le n for each query; bi∈{0,1}b_i\in\{0,1\} for every 1≤i≤n1\le i\le n.

Example 1

Input

4 2
1 1 0 1
1 2
2 4

Output

YES
NO

Explanation

Interval [1,2][1,2] contains 1,1 and is valid. Interval [2,4][2,4] contains 1,0,1, so position 3 makes it invalid.