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绘图:
随机推荐
- 【并发那些事】线程有序化神器CompletionService
前言 话说有一天,产品经理突然找到正在摸鱼的你. 产品:『我们要加一个聚合搜索功能,当用户在我们网站查询一件商品时,我们分别从 A.B.C 三个网站上查询这个信息,然后再把得到的结果返回给用户』 你: ...
- sqlalchemy_mptt一次调优
问题背景: 我用sqlalchemy_mptt构建了一个多级分类项目,数据库用了sqlite.随着数据条数越来越多,写入速度逐渐变慢,一棵树的插入甚至需要1分钟,远远不能满足需求 分析思路: 1. 批 ...
- ASP.NET MVC 给Action的参数赋值的方式
Action指的是Controller类中的方法,如上文中的Index. Action参数的三种常见类型:Model类型.普通参数.FormCollection Model类型 我们可以直接在地址栏后 ...
- Wannafly Camp 2020 Day 6F 图与三角形 - 图论
把黑边视为无边,那么答案之和每个点的度数有关 #include <bits/stdc++.h> using namespace std; #define int long long int ...
- Wannafly Camp 2020 Day 3A 黑色气球
#include <bits/stdc++.h> using namespace std; int a[1005][1005],n,x[1005]; int main() { scanf( ...
- mycat linux上目录介绍
1.本文引用来自mycat官方文档,具体可以浏览mycat官网 2.linux系统下面的目录 MyCAT 有提供编译好的安装包,支持 windows.Linux.Mac.Solaris 等系统上安装与 ...
- TAB_JG_COMMAND_SERVERINFO
简介 存储设备基本信息 表结构
- pymysql模块学习
#Pymysql 用于连接mysql数据库 #连接数据库 data_ip = "192.168.34.128" data_name = "lch" data_p ...
- 如何把U盘的两个盘或者多个盘合成一个
1.插入U盘,导出所有重要数据. 2.右击我的电脑,点管理打开设备管理器. 3.在设备管理器里找到磁盘管理. 4.在磁盘管理右侧出现下图: 5.如图是windows 7的界面. 6.找到U盘,图上是磁 ...
- Python入门8 —— 逻辑运算符补充
一:优先级:not > and > or 1.not与紧跟其后的那个条件是不可分割的 2.如果条件语句全部由纯and.或纯or链接,按照从左到右的顺序依次计算即可 print(True a ...