Eugeny has array a = a1, a2, ..., an, consisting of n integers. Each integer ai equals to -1, or to 1. Also, he has m queries:

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

Help Eugeny, answer all his queries.

Input

The first line contains integers n and m (1 ≤ n, m ≤ 2·105). The second line contains n integers a1, a2, ..., an (ai = -1, 1). Next m lines contain Eugene's queries. The i-th line contains integers li, ri (1 ≤ li ≤ ri ≤ n).

Output

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

Examples

Input
2 3
1 -1
1 1
1 2
2 2
Output
0
1
0
Input
5 5
-1 1 1 1 -1
1 1
2 3
3 5
2 5
1 5
Output
0
1
0
1
0
题意:问这一组数重排后,能不能使区间[l,r]的和为0
这题就在卡输入
代码:
#include<iostream>
using namespace std;
int main(){
ios::sync_with_stdio(false);//c++加速语句
int n,m;
cin>>n>>m;
int cnt1=,cnt2=;
while(n--){
int a;
cin>>a;
if(a>) cnt1++;
else cnt2++;
}
int minn=min(cnt1,cnt2);
while(m--){
int l,r;
cin>>l>>r;
if((r-l+)%==&&(r-l+)/<=minn) cout<<""<<endl;
else cout<<""<<endl;
}
return ;
}

Eugeny and Array(思维)的更多相关文章

  1. Eugeny and Array(水题,注意题目描述即可)

    Eugeny has array a = a1, a2, ..., an, consisting of n integers. Each integer ai equals to -1, or to ...

  2. Beauty of Array(思维)

    Beauty of Array Time Limit: 2 Seconds      Memory Limit: 65536 KB Edward has an array A with N integ ...

  3. LCP Array(思维)

    LCP Array Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Tota ...

  4. Codeforces 950D A Leapfrog in the Array (思维)

    题目链接:A Leapfrog in the Array 题意:给出1-n的n个数,从小到大每隔一个位置放一个数.现在从大到小把数往前移动,每次把最右边的数移动最靠右边的空格处直到n个数都在前n个位置 ...

  5. CF949B A Leapfrog in the Array 思维题,推理

    题意: Dima是一名初级程序员. 在他的工作中,他经常不断地重复以下操作:从数组中删除每个第二个元素. 有一天,他对这个问题的解决方案感到厌倦,他提出了以下华丽的算法. 假设有一长度为2n的数组,最 ...

  6. Codeforces 950D A Leapfrog in the Array ( 思维 && 模拟 )

    题意 : 给出 N 表示有标号 1~N 的 N 个数,然后从下标 1 开始将这 N 个数每隔一位放置一个,直到 N 个数被安排完,现在有一个操作就是每次将数列中最右边的数向离其左边最近的空缺处填上,一 ...

  7. Codeforces Round #643 (Div. 2) D. Game With Array (思维,构造)

    题意:给你两个正整数\(N\)和\(S\),构造一个长度为\(N\)并且所有元素和为\(S\)的正整数数组,问是否能找到一个\(K (0\le K \le S)\)使得这个数组的任意_子数组_的和都不 ...

  8. Codeforces Round #182 (Div. 1 + Div. 2)

    A. Eugeny and Array \(r-l+1\)是奇数时,和显然无法为0. 奇数的情况需要判断-1和1的个数是否大于等于长度的一半. B. Eugeny and Play List 模拟. ...

  9. 思维导图(自己整理,希望对大家有用):JavaScript函数+canvas绘图+Array数组

    1.javascript函数: 2.Array数组: 3.canvas绘图:

随机推荐

  1. 【JavaScript Weekly】#471 — JANUARY 17, 2020

    https://javascriptweekly.com/issues/471 #471 — JANUARY 17, 2020 READ ON THE WEB JavaScript Weekly Ba ...

  2. mysql 行锁 表锁

    MySQL数据库 - 引擎: - innodb - 支持事务 - 锁 - 行锁 - 表锁 - 示例: - 终端: begin; select xx from xx for update; commit ...

  3. 栈和队列----设计一个有getMin功能的栈

    设计一个有getMin功能的栈 设计一个具有getMin功能的栈,可以返回栈中的最小的元素,可以使用现有的栈的数据结构,要求pop/push/getMin操作的时间复杂度是O(1). package ...

  4. 异常处理_python

    一.异常处理格式: name=[1,2]data={}try: name[3] data['name']except (KeyError,IndexError) as e : #捕捉指定的几个错误类型 ...

  5. Wannafly Camp 2020 Day 1F 乘法 - 字符串

    一开始想根据单调性双指针 后来血了才想起来负负得正 于是暴力二分答案即可 #include <bits/stdc++.h> using namespace std; #define int ...

  6. Tomcat的使⽤

    准备 1.官⽹地址:http://tomcat.apache.org下载. 2.解压文件,并放到指定路径,给该文件授权. chmod -R 755 3.启动和停止 进入到/Users/lucas/Do ...

  7. 表结构修改以及sql增删改查

    修改表结构 修改表名 alter table 表名 rename 新名 增加字段 alter table 表名 add 字段名 数据类型 约束 删除字段 alter table 表名 drop 字段名 ...

  8. eclipse的安装和环境配置

    一,eclipse下载 地址:https://www.eclipse.org/downloads/ 一般浏览器都有翻译功能 二.有32位和64位的版本根据自己的需求下载,选下载的选下载量最多的下载. ...

  9. Unable to connect to a repository at URL

    缓存问题: 1. 右键点击本地副本,TortoiseSVN -> Settings -> Saved Data, 2.点击“Clear”按钮,把本地缓存都清除了,点击“确定”: 3. 再重 ...

  10. linux中的oracle数据库

    安装orcal http://www.cnblogs.com/nucdy/p/5603998.html 搭建Linux操作系统+Oracle数据库的环境 https://blog.csdn.net/p ...