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. JavaSE学习笔记(1)---数据类型、运算符、控制结构

    javaSE学习笔记(1) 数据类型和运算符 1.注释可以提高程序的可读性.可划分为 单行注释 // 多行注释 /.../ 文档注释 /**...*/ 2.标识符的命名规则: 标识符必须以字母.下划线 ...

  2. ES6实现图片切换特效

    效果图 demo.html <!DOCTYPE html> <html lang="en"> <head> <meta charset=& ...

  3. react-native构建基本页面2---轮播图+九宫格

    配置首页的轮播图 轮播图官网 运行npm i react-native-swiper --save安装轮播图组件 导入轮播图组件import Swiper from 'react-native-swi ...

  4. 将自定义工程加入到python根目录下

    1. 在D:\Program Files\Python\Lib\site-packages 添加.pth文件,文件名为模块名称(即auto_XXX),文件内容为模块所在目录.(python添加自定义的 ...

  5. SmartSVN:File has inconsistent newlines

    用SmartSVN提交文件的时候,提示svn: File has inconsistent newlines 这是由于要提交的文件编码时混合了windows和unix符号导致的. 解决方案 Smart ...

  6. C++——浅拷贝

    10.深拷贝与浅拷贝 浅拷贝: 实现对象间数据元素的一一对应赋值:(默认构造函数) 深拷贝: 当被复制的对象数据成员是指针类型时,不是复制该指针成员本身,而是将指针所指的对象进行复制. //浅拷贝 # ...

  7. ZJOI2006 书架 lg2596

    题面见https://www.luogu.org/problemnew/show/P2596 题面就是描述了一个书柜从上到下放着书,可以看作一个序列,每个数的序号为它在从上向下数第几本 一开始建树偷了 ...

  8. opencv图像坐标

    原图: 尺寸:240 × 150 灰度化: 1. 程序中输出像素点的灰度值: 2. 用工具取得的灰度值: 按照如下的坐标(图像处理坐标系) 得到的灰度值: (35,82) (82,35) 换算后分别是 ...

  9. Java时间格式字符串与Date的相互转化

    目录 将Date转化为格式化字符串 时间格式字符串转化为Date @ 将Date转化为格式化字符串 将Date转化为格式化字符串是利用SimpleDateFormat类继承自 java.text.Da ...

  10. C# asp.net 配置文件连接sql 数据库

    先引用 using System.Configuration;//配置文件using System.Data.SqlClient; 我这里使用的是SqlServer 2008  sa 用户 密码也为s ...