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\) 求树的最大匹配和其个数 来 ...
随机推荐
- 影响Cache的几个HTTP头信息【转载http://hi.baidu.com/feilala_fly/item/f79eca08fbf389026c9048a7】
Http的Cache机制总共有4个组成部分: Cache-Control.Last-Modified(If-Modified-Since).Etag(If-None-Match) .Expires 服 ...
- ACM学习历程—广东工业大学2016校赛决赛-网络赛F 我是好人4(数论)
题目链接:http://gdutcode.sinaapp.com/problem.php?cid=1031&pid=5 这个题目一看就是一道数论题,应该考虑使用容斥原理,这里对lcm进行容斥. ...
- iPhone X机型适配
1.启动页 启动App,发现App只能居中显示,不能上下充满. 问题产生的原因是:iPhone X是5.8英寸,比5.5英寸的屏幕还要大,没有合适的启动页可以加载,所以只能使用以前5.5英寸的启动页, ...
- 洛谷 P4220 & UOJ #347 通道 —— 随机化
题目:https://www.luogu.org/problemnew/show/P4220 http://uoj.ac/problem/347 先写了一下 n^2 和三棵树一样的情况,n^2 还写了 ...
- Poj 2503 Babelfish(Map操作)
一.Description You have just moved from Waterloo to a big city. The people here speak an incomprehens ...
- 优秀开源项目之三:高性能、高并发、高扩展性和可读性的网络服务器架构State Threads
译文在后面. State Threads for Internet Applications Introduction State Threads is an application library ...
- CUDA V9.2 sample编译问题
这个哥们也遇到一样的问题 CUDA 9.1/9.2 与 Visual Studio 2017 (VS2017 15.6.4) 的不兼容问题 错误有显示 #if _MSC_VER < 1600 | ...
- ng2 中使用echart
1.首先创建echarts指令 //echart.directive.ts important { Directive,ElementRef,Input,Ouput,Onchanges,OnInit, ...
- 《精通Spring4.X企业应用开发实战》读后感第六章(引用Bean的属性值)
- <c和指针>学习笔记6输入输出函数
1 错误报告 (1)perror函数 void perror(char const *message) error是标准库的一个外部整型变量(errno.h),保存错误代码之后就会把这个信息传递给用户 ...