Eugeny and Array(水题,注意题目描述即可)
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 li, ri (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(水题,注意题目描述即可)的更多相关文章
- hdu 5532 Almost Sorted Array (水题)
Almost Sorted Array Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Ot ...
- CF451B Sort the Array 水题
Codeforces Round #258 (Div. 2) Sort the Array B. Sort the Array time limit per test 1 second memory ...
- 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 ...
- 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 ...
- codeforces 660A A. Co-prime Array(水题)
题目链接: A. Co-prime Array time limit per test 1 second memory limit per test 256 megabytes input stand ...
- 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 ...
- CodeForces-831A-Unimodal Array (水题)
题目链接 /* Name: Copyright: Author: Date: 2018/5/6 19:34:23 Description: */ #include <iostream> # ...
- 11.07图论水题Test
11.07图论水题Test 题目 描述 做法 \(BSOJ6378\) 在\(i\)位置可以到\(i+a_i\)或\(i+b_i\)求\(1\rightarrow n\)字典序最小路径 判可达性后贪心 ...
- 11.06水题Test
11.06水题比赛 题目 描述 做法 \(BSOJ5150\) 求\(n\)个数两两之差的中位数 二分中位数,双指针判定\(\le x\)差值对数 \(BSOJ5151\) 求树的最大匹配和其个数 来 ...
随机推荐
- bzoj 1355: Radio Transmission
题目大意: 求字符串的最短循环覆盖字符串 题解: 经典结论题: kmp \(ans = n - next[n]\) #include <cstdio> #include <cstri ...
- Popular Cows
传送门(poj):http://poj.org/problem?id=2186 (bzoj):http://www.lydsy.com/JudgeOnline/problem.php?id=1051 ...
- java判断一个类是否公共类
Modifier.isPublic([类].getModifiers()) Modifier.isAbstract([类].getModifiers())
- 如何恢复,迁移,添加, 删除 Voting Disks
如何恢复,迁移,添加, 删除 Voting Disks恢复流程 在11gR2 之前,我们可以直接直接使用dd命令对voting disk进行备份.DD示例 备份votedisk盘:[root@raw1 ...
- 用遗传算法解决TSP问题
浅谈遗传算法:https://www.cnblogs.com/AKMer/p/9479890.html Description \(小m\)在踏上寻找\(小o\)的路程之后不小心碰到了大魔王\(fat ...
- 百度地图设置div样式宽高为百分比不显示地图
如题,不显示地图只要在样式代码里面加以 position:absolute; 代码就可以了 <style type="text/css"> body, html,#al ...
- RPM包及其管理 rpm命令
一.什么是RPMRPM:RedHat Package Manager //红帽包管理如果Linux发行版本是redhat .redflag .centos .fedora .suse等或者衍生 ...
- DCloud-MUI:Hello MUI2
ylbtech-DCloud: 1. <head> <meta charset="utf-8"> <title>Hello MUI</ti ...
- 为什么并行测试很困难以及如何使用 ConTest 辅助测试
众所周知并行程序设计易于产生 bug.更为严重的是,往往在开发过程的晚期当这些并行 bug 引起严重的损害时才能发现它们并且难于调试它们.即使彻底地对它们进行了调试,常规的单元测试实践也很可能遗漏并行 ...
- CCNet说明文档
1.CCNet安装步骤 1) 安装CCNet服务器端:CruiseControl.NET-1.8.5.0-Setup.exe 2) 安装CCNet客户端:CruiseControl.NET ...