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

代码

#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm> using namespace std; int main() {
int n,m;
int num[200005];
cin>>n>>m;
int sum1=0,sum2=0;
for(int t=0; t<n; t++) {
scanf("%d",&num[t]);
if(num[t]==-1) {
sum1++;
} else {
sum2++;
}
}
int l,r;
for(int t=0; t<m; t++) {
scanf("%d%d",&l,&r);
if((r-l)%2==0)
printf("0\n");
else if((r-l)%2!=0) {
if((r-l+1)/2<=sum1&&(r-l+1)/2<=sum2)
printf("1\n");
else
printf("0\n");
}
} return 0;
}

Eugeny and Array(水题,注意题目描述即可)的更多相关文章

  1. hdu 5532 Almost Sorted Array (水题)

    Almost Sorted Array Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Ot ...

  2. CF451B Sort the Array 水题

    Codeforces Round #258 (Div. 2) Sort the Array B. Sort the Array time limit per test 1 second memory ...

  3. Codeforces Round #331 (Div. 2) B. Wilbur and Array 水题

    B. Wilbur and Array Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/596/p ...

  4. Educational Codeforces Round 11 A. Co-prime Array 水题

    A. Co-prime Array 题目连接: http://www.codeforces.com/contest/660/problem/A Description You are given an ...

  5. codeforces 660A A. Co-prime Array(水题)

    题目链接: A. Co-prime Array time limit per test 1 second memory limit per test 256 megabytes input stand ...

  6. codeforces 558B B. Amr and The Large Array(水题)

    题目链接: B. Amr and The Large Array time limit per test 1 second memory limit per test 256 megabytes in ...

  7. CodeForces-831A-Unimodal Array (水题)

    题目链接 /* Name: Copyright: Author: Date: 2018/5/6 19:34:23 Description: */ #include <iostream> # ...

  8. 11.07图论水题Test

    11.07图论水题Test 题目 描述 做法 \(BSOJ6378\) 在\(i\)位置可以到\(i+a_i\)或\(i+b_i\)求\(1\rightarrow n\)字典序最小路径 判可达性后贪心 ...

  9. 11.06水题Test

    11.06水题比赛 题目 描述 做法 \(BSOJ5150\) 求\(n\)个数两两之差的中位数 二分中位数,双指针判定\(\le x\)差值对数 \(BSOJ5151\) 求树的最大匹配和其个数 来 ...

随机推荐

  1. Java基础 之 System.getProperty()方法

    Java基础 之 System.getProperty()方法大全 public static void main(String[] args) { System.out.println(" ...

  2. redis安装及启动及设置

    1. 安装 1.1 下载解压包,直接解压到任意路径下即可 windows下载地址:ttps://github.com/MSOpenTech/redis/releases 2.启动 2.1 启动要先开启 ...

  3. JavaScript-Tool-富文本:UEditor

    ylbtech-JavaScript-Tool-富文本:UEditor UEditor是由百度WEB前端研发部开发的所见即所得的开源富文本编辑器,具有轻量.可定制.用户体验优秀等特点.开源基于BSD协 ...

  4. 3 K8s安裝ELK+filebeat

    1 Filebeat: apiVersion: v1 kind: Service metadata: name: XX spec: ports: - name: http port: targetPo ...

  5. logback 相关

    %logger{36} 表示logger名字最长36个字符,否则按照句点分割. %X{key} to get the value that are stored in the MDC map ${lo ...

  6. uva 512

    1. 问题 不知道怎么存储操作 看代码注释,else if等 2. 代码 #include <iostream> #include <stdio.h> #include < ...

  7. SM4算法的c++实现

    百度到的论文已给出算法. flag为1为解密,flag为0是加密. #include<bits/stdc++.h> using namespace std; typedef long lo ...

  8. 【总结整理】关于Json的解析,校验和验证

    var jasondata='{"staff": [{"name":"红旗","age":90}, {"nam ...

  9. SpringBoot02 Controller的使用、数据库操作、事物管理、修改banner

    1 Controller的使用 特点:编程技巧和SpringMVC几乎完全一样 注意:@RestController = @Controller + @ResponseBody 注意:读取路径参数和请 ...

  10. vue.js基础学习(1)

    一:v-cloak:解决浏览器闪烁,编译过程中不会显示,直到编译结束才显示. 用法:[v-cloak] { display: none;} <div v-cloak> {{ message ...