// Codeforces Round #182 (Div. 2) A Eugeny and Array
import java.io.*;
import java.math.*;
import java.util.*;
import org.omg.CORBA.Environment;
//Codeforces
public class MainCodeforces1 {
private static MyScanner in;
private static PrintStream out;
private static boolean LOCAL_TEST = false;
private static void solve() throws IOException
{
int N = in.nextInt();
int M = in.nextInt();
int numPos = 0;
int numNeg = 0;
String line = in.nextLine();
String[] aline = line.split(" ");
for (int i = 0; i < N; i++) {
int x = Integer.valueOf(aline[i]);
if (x == 1)
numPos++;
else
numNeg++;
}
StringBuilder sb = new StringBuilder("");
for (int i = 0; i < M; i++) {
int l = in.nextInt();
int r = in.nextInt();
int num = r - l + 1;
if (num % 2 == 0) {
if (numPos >= num / 2 && numNeg >= num / 2)
sb.append("1\n");
else
sb.append("0\n");
}
else {
sb.append("0\n");
}
}
out.println(sb.toString());
}
public static void main(String[] args) throws IOException {
// helpers for input/output
out = System.out;
try {
String cname = System.getenv("COMPUTERNAME");
LOCAL_TEST = (cname.equals("ALPHA530"));
} catch (Exception e) {
}
if (LOCAL_TEST) {
in = new MyScanner("E:\\zin.txt");
}
else {
boolean usingFileForIO = false;
if (usingFileForIO) {
// using input.txt and output.txt as I/O
in = new MyScanner("input.txt");
out = new PrintStream("output.txt");
}
else {
in = new MyScanner();
out = System.out;
}
}
solve();
}
// =====================================
static class MyScanner {
Scanner inp = null;
public MyScanner() throws IOException
{
inp = new Scanner(System.in);
}
public MyScanner(String inputFile) throws IOException {
inp = new Scanner(new FileInputStream(inputFile));
}
public int nextInt() throws IOException {
return inp.nextInt();
}
public long nextLong() throws IOException {
return inp.nextLong();
}
public double nextDouble() throws IOException {
return inp.nextDouble();
}
public String nextString() throws IOException {
return inp.next();
}
public String nextLine() throws IOException {
inp.nextLine();
return inp.nextLine();
}
}
}
No comments:
Post a Comment