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. Codeforces Round #616 (Div. 2) C. Mind Control

    题目链接:http://codeforces.com/contest/1291/problem/C 思路: 我们可以很容易想到,只有前m-1个人才能影响m的选择的大小,后面的人无法影响. 如果所有人都 ...

  2. Qt 程序打包发布总结 转

    1.  概述 当我们用QT写好了一个软件,要把你的程序分享出去的时候,不可能把编译的目录拷贝给别人去运行.编译好的程序应该是一个主程序,加一些资源文件,再加一些动态链接库,高大上一些的还可以做一个安装 ...

  3. usim卡介绍

  4. LED Keychain: Timeless Business Gift

    Every business owner understands the importance of reducing marketing budgets and investing in sales ...

  5. 我的python笔记05

    Python 之路 Day5 - 常用模块学习 本节大纲: 模块介绍 time &datetime模块 random os sys shutil json & picle shelve ...

  6. 2020牛客寒假算法基础集训营5 G.街机争霸 (bfs)

    https://ac.nowcoder.com/acm/problem/201961 预处理出僵尸走的路径,僵尸走的周期长度应该为2k-2,在普通的bfs基础上加上一维表示时间,从当前位置x,y和和时 ...

  7. AE开发常见问题总结

    一. Arcgis10.0 组件初始化失败解决方法: ESRI.ArcGIS.RuntimeManager.BindLicense(ESRI.ArcGIS.ProductCode.EngineOrDe ...

  8. Jmeter-几种脚本录制方式

    一.使用代理服务器进行录制 1.创建线程组 2.创建http代理服务器 分组解释 不对样本分组:所有请求全部罗列 在组件添加分隔:加入一个虚拟的以分割线命名的动作 每个组放入一个新的控制器:执行时按控 ...

  9. PHP 把秒数转为时分秒格式

    PHP函数 1.gmdate $seconds = 174940;$hours = intval($seconds/); $time1 = $hours."小时".gmdate(' ...

  10. Mybatis-生成逆向工程后对数据库的模糊查询详解

    MyBatis-使用逆向工程中方法进行模糊查询 1.应用mybatis逆向工程会大大的提高我们的开发效率,如何应用mabatis 逆向生成的代码进行模糊查询那. 2.首先看一下pojo 层中examp ...