CF302A.Eugeny and Array

普及/提高-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Eugeny has array a = _a_1, _a_2, ..., a__n, consisting of n integers. Each integer a__i equals to -1, or to 1. Also, he has m queries:

  • Query number i is given as a pair of integers l__i, r__i (1 ≤ l__i ≤ r__i ≤ n).
  • The response to the query will be integer 1, if the elements of array a can be rearranged so as the sum a__l__i + a__l__i + 1 + ... + a__r__i = 0, otherwise the response to the query will be integer 0.

Help Eugeny, answer all his queries.

尤金有一个由 nn 个整数组成的数组 a=a1,a2,…,ana = a_1, a_2, \dots, a_n。每个整数 aia_i 的值为 −1-1 或 11。此外,他还有 mm 个查询:

  • 第 ii 个查询以一对整数 li,ril_i, r_i 给出(满足 1≤li≤ri≤n1 \leq l_i \leq r_i \leq n);
  • 对该查询的回答为整数 11,当且仅当数组 aa 的元素可以被重新排列,使得子段和 ali+ali+1+⋯+ari=0a_{l_i} + a_{l_i+1} + \dots + a_{r_i} = 0;否则回答为整数 00。

请帮助尤金回答所有查询。

输入格式

The first line contains integers n and m (1 ≤ n, m ≤ 2·105). The second line contains n integers _a_1, _a_2, ..., a__n (a__i = -1, 1). Next m lines contain Eugene's queries. The i-th line contains integers l__i, r__i (1 ≤ l__i ≤ r__i ≤ n).

第一行包含两个整数 nn 和 mm(1 ≤ n, m ≤ 2⋅1051 \le n, m \le 2\cdot10^5)。第二行包含 nn 个整数 a1, a2, ..., ana_1, a_2, ..., a_n(其中每个 ai = −1a_i = -1 或 11)。接下来的 mm 行是尤金的查询。第 ii 行包含两个整数 lil_i、rir_i(1 ≤ li ≤ ri ≤ n1 \le l_i \le r_i \le n)。

输出格式

Print m integers — the responses to Eugene's queries in the order they occur in the input.

输出 m 个整数——即尤金查询的响应结果,按输入中出现的顺序输出。

输入输出样例

  • 输入#1

    2 3
    1 -1
    1 1
    1 2
    2 2

    输出#1

    0
    1
    0
  • 输入#2

    5 5
    -1 1 1 1 -1
    1 1
    2 3
    3 5
    2 5
    1 5

    输出#2

    0
    1
    0
    1
    0

输入解题思路,AI测评打分。不知道怎么写?

首页