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
2 3
1 -1
1 1
1 2
2 2
0
1
0
5 5
-1 1 1 1 -1
1 1
2 3
3 5
2 5
1 5
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(思维)的更多相关文章
- Eugeny and Array(水题,注意题目描述即可)
		
Eugeny has array a = a1, a2, ..., an, consisting of n integers. Each integer ai equals to -1, or to ...
 - Beauty of Array(思维)
		
Beauty of Array Time Limit: 2 Seconds Memory Limit: 65536 KB Edward has an array A with N integ ...
 - LCP Array(思维)
		
LCP Array Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) Tota ...
 - Codeforces 950D  A Leapfrog in the Array (思维)
		
题目链接:A Leapfrog in the Array 题意:给出1-n的n个数,从小到大每隔一个位置放一个数.现在从大到小把数往前移动,每次把最右边的数移动最靠右边的空格处直到n个数都在前n个位置 ...
 - CF949B A Leapfrog in the Array 思维题,推理
		
题意: Dima是一名初级程序员. 在他的工作中,他经常不断地重复以下操作:从数组中删除每个第二个元素. 有一天,他对这个问题的解决方案感到厌倦,他提出了以下华丽的算法. 假设有一长度为2n的数组,最 ...
 - Codeforces 950D A Leapfrog in the Array ( 思维 && 模拟 )
		
题意 : 给出 N 表示有标号 1~N 的 N 个数,然后从下标 1 开始将这 N 个数每隔一位放置一个,直到 N 个数被安排完,现在有一个操作就是每次将数列中最右边的数向离其左边最近的空缺处填上,一 ...
 - Codeforces Round #643 (Div. 2) D. Game With Array (思维,构造)
		
题意:给你两个正整数\(N\)和\(S\),构造一个长度为\(N\)并且所有元素和为\(S\)的正整数数组,问是否能找到一个\(K (0\le K \le S)\)使得这个数组的任意_子数组_的和都不 ...
 - Codeforces Round #182 (Div. 1 + Div. 2)
		
A. Eugeny and Array \(r-l+1\)是奇数时,和显然无法为0. 奇数的情况需要判断-1和1的个数是否大于等于长度的一半. B. Eugeny and Play List 模拟. ...
 - 思维导图(自己整理,希望对大家有用):JavaScript函数+canvas绘图+Array数组
		
1.javascript函数: 2.Array数组: 3.canvas绘图:
 
随机推荐
- ipa文件信息检查工具
			
项目地址:https://github.com/ryjwinner/softwares/raw/master/iOS-checkIPA.jar 项目简介: 针对近期大量iOS app需要签名,但多家签 ...
 - 搜索字母a或A
			
Amy觉得英语课实在是无聊至极,他不喜欢听老师讲课. 但是闲着也是闲着,不如做点什么吧?于是他开始数英语书里的字母a和A共出现了多少次. 费了九牛二虎之力终于数完了. 作为一名软件工程专业大学生,他觉 ...
 - ssh排错思路
			
telnet远程22端口refused 先netstat -utnlp 看一下22端口监听状态(一般都不在监听) 然后systemctl restart sshd 如果有报错,执行sshd - ...
 - 转载:openmax bellagio
			
https://wenku.baidu.com/view/18472c1387c24028915fc3e9.html https://wenku.baidu.com/view/1e380bc20c22 ...
 - C++——标准模板库
			
1.泛型程序设计:将程序尽可能写的通用,将算法从特定的数据结构中抽象出来,成为通用的:C++模板为泛型程序设计奠定了关键的基础:STL是泛型程序设计的一个范例:容器container.迭代器itera ...
 - SSM项目集成Lucene+IKAnalyzer在Junit单元测试中执行异常
			
个人博客 地址:http://www.wenhaofan.com/article/20181108132519 问题描述 在项目运行以及main方法中能够正常运行,但是使用junit单元测试时却报如下 ...
 - Maven无法下载com.oracle:ojdbc14:jar解决方法
			
问题说明:导入Maven项目时,想要添加Oracle驱动包时,Maven的pom.xml总是报Missing artifact com.oracle:ojdbc14:jar:10.2.0.1.0错. ...
 - thinkphp中如何用路由调用前台html界面
			
先上图片看看基本的文件位置 1.首先在application\route.php中定义路由 <?php use think\Route; Route::get("home", ...
 - gflag的简单入门demo
			
gflags 一. 下载与安装 这里直接使用包管理器安装: sudo apt install libgflags-dev 二. gflags的简单使用 1. 定义需要的类型 格式: DEFINE_类型 ...
 - Java  Set集合的详解
			
一,Set Set:注重独一无二的性质,该体系集合可以知道某物是否已近存在于集合中,不会存储重复的元素 用于存储无序(存入和取出的顺序不一定相同)元素,值不能重复. 对象的相等性 引用到堆上同一个对象 ...