Codeforces Round #182 (Div. 2) / 302A Eugeny and Array(模拟)
2013-08-14 10:59
573 查看
A. Eugeny and Array
http://codeforces.com/problemset/problem/302/A
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
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 mlines 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.
Sample test(s)
input
output
input
output
写第一遍没看清题意,样例2看不懂,后来发现我确实要补补英语了。。(不过这句话确实很容易漏掉)
原文有这么一句话:
" if the elements of array a can
be rearranged ..."(如果序列a中元素经过重新排列后…)
完整代码:
http://codeforces.com/problemset/problem/302/A
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
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 mlines 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.
Sample test(s)
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 01
0
写第一遍没看清题意,样例2看不懂,后来发现我确实要补补英语了。。(不过这句话确实很容易漏掉)
原文有这么一句话:
" if the elements of array a can
be rearranged ..."(如果序列a中元素经过重新排列后…)
完整代码:
/*171ms,0KB*/ #include<cstdio> int main() { int n, m, a; int c1 = 0, c2 = 0; int l, r; scanf("%d%d", &n, &m); while (n--) { scanf("%d", &a); if (a > 0) ++c1; else ++c2; } while (m--) { scanf("%d%d", &l, &r); a = r - l + 1;///第一次交的时候这里写反了,WA4,罪过,罪过。。。 if (a & 1) puts("0"); else { a >>= 1; puts(c1 < a || c2 < a ? "0" : "1"); } } return 0; }
相关文章推荐
- 【Codeforces Round 335 (Div 2) B】【模拟】Testing Robots 机器人逐步走 走到矿场就爆炸的最多行走步数
- Codeforces Round #Pi (Div. 2)567B Berland National Library(模拟)
- Codeforces Round #331 (Div. 2)-Wilbur and Array(贪心模拟)
- Codeforces Round #158 (Div. 2) C. Balls and Boxes 模拟
- Codeforces Round #182 (Div. 2)
- Codeforces Round #182 (Div. 1) Yaroslav and Divisors(离线+树状数组)
- Codeforces Round #281 (Div. 2) A. Vasya and Football 模拟
- Codeforces Round #350 (Div. 2) F. Restore a Number 模拟构造题
- Codeforces Round #202 (Div. 2)B. Color the Fence(贪心,模拟)
- Codeforces Round #195 (Div. 2) / 336A Vasily the Bear and Triangle(模拟&数学)
- Codeforces Beta Round #35 (Div. 2) / 35A Shell Game(模拟)
- Codeforces Round #343 (Div. 2) -A. Far Relative’s Birthday Cake(组合+模拟)
- Codeforces Round #380 (Div. 2) B. Spotlights (模拟)
- 【Codeforces Round 336 (Div 2) E】【KMP 构造 脑洞 好题 模拟找规律】Marbles 两条路径同时出发前后行走能否恰好同时到终点
- Codeforces Beta Round #98 (Div. 2) / 137A Postcards and photos (模拟)
- Codeforces Round #354 (Div. 2) B. Pyramid of Glasses (模拟+思维)
- Codeforces Round #425 (Div. 2) B. Petya and Exam【模拟】
- Codeforces Round #376 (Div. 2)F(前缀和,模拟)
- Codeforces Round #158 (Div. 2)C. Balls and Boxes(模拟)
- Codeforces Round #321 (Div. 2) Kefa and First Steps 模拟