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.
尤金有一个由 n 个整数组成的数组 a=a1,a2,…,an。每个整数 ai 的值为 −1 或 1。此外,他还有 m 个查询:
- 第 i 个查询以一对整数 li,ri 给出(满足 1≤li≤ri≤n);
- 对该查询的回答为整数 1,当且仅当数组 a 的元素可以被重新排列,使得子段和 ali+ali+1+⋯+ari=0;否则回答为整数 0。
请帮助尤金回答所有查询。
输入格式
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).
第一行包含两个整数 n 和 m(1 ≤ n, m ≤ 2⋅105)。第二行包含 n 个整数 a1, a2, ..., an(其中每个 ai = −1 或 1)。接下来的 m 行是尤金的查询。第 i 行包含两个整数 li、ri(1 ≤ li ≤ ri ≤ 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测评打分。不知道怎么写?