codeforces705B B. Spider Man

来源:互联网 发布:网络会员制营销好处 编辑:程序博客网 时间:2024/05/17 01:58
B. Spider Man
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Peter Parker wants to play a game with Dr. Octopus. The game is about cycles. Cycle is a sequence of vertices, such that first one is connected with the second, second is connected with third and so on, while the last one is connected with the first one again. Cycle may consist of a single isolated vertex.

Initially there are k cycles, i-th of them consisting of exactly vi vertices. Players play alternatively. Peter goes first. On each turn a player must choose a cycle with at least 2 vertices (for example, x vertices) among all available cycles and replace it by two cycles with p andx - p vertices where 1 ≤ p < x is chosen by the player. The player who cannot make a move loses the game (and his life!).

Peter wants to test some configurations of initial cycle sets before he actually plays with Dr. Octopus. Initially he has an empty set. In thei-th test he adds a cycle with ai vertices to the set (this is actually a multiset because it can contain two or more identical cycles). After each test, Peter wants to know that if the players begin the game with the current set of cycles, who wins?

Peter is pretty good at math, but now he asks you to help.

Input

The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — the number of tests Peter is about to make.

The second line contains n space separated integers a1, a2, ..., an (1 ≤ ai ≤ 109), i-th of them stands for the number of vertices in the cycle added before the i-th test.

Output

Print the result of all tests in order they are performed. Print 1 if the player who moves first wins or 2 otherwise.

Examples
input
31 2 3
output
211
input
51 1 5 1 1
output
22222
Note

In the first sample test:

In Peter's first test, there's only one cycle with 1 vertex. First player cannot make a move and loses.

In his second test, there's one cycle with 1 vertex and one with 2. No one can make a move on the cycle with 1 vertex. First player can replace the second cycle with two cycles of 1 vertex and second player can't make any move and loses.

In his third test, cycles have 12 and 3 vertices. Like last test, no one can make a move on the first cycle. First player can replace the third cycle with one cycle with size 1 and one with size 2. Now cycles have 1122 vertices. Second player's only move is to replace a cycle of size 2 with 2 cycles of size 1. And cycles are 11112. First player replaces the last cycle with 2 cycles with size 1 and wins.

In the second sample test:

Having cycles of size 1 is like not having them (because no one can make a move on them).

In Peter's third test: There a cycle of size 5 (others don't matter). First player has two options: replace it with cycles of sizes 1 and 4 or 2and 3.

  • If he replaces it with cycles of sizes 1 and 4: Only second cycle matters. Second player will replace it with 2 cycles of sizes 2. First player's only option to replace one of them with two cycles of size 1. Second player does the same thing with the other cycle. First player can't make any move and loses.
  • If he replaces it with cycles of sizes 2 and 3: Second player will replace the cycle of size 3 with two of sizes 1 and 2. Now only cycles with more than one vertex are two cycles of size 2. As shown in previous case, with 2 cycles of size 2 second player wins.

So, either way first player loses.

这题比赛时没做出来,比赛后躺在床上想了想。于是就证明出来了。我发现我真是智障。。。

下面简单记录下证明过程:先考虑只有一段时(这里假设长度为p),当p=1时,这时后手肯定赢,这没什么好说的。。

当p>1 时,且p%2==1时后手一定赢,因为无论先手一开始把p分为什么形式,一定是分为一奇一偶的,这时后手只需要把那个偶数(假设为q),分为1和q-1这时q-1又为奇数了,递推下去一定可以推到qn=2时,这时2这段永远是被后手分为1和1两段的,这时先手只能去分剩下的奇数。所以当p为奇数时后手必胜。

当p%2==0时,先手一定获胜,很简单,先手只需要每次把p分为1 和p-1 由于p为偶数,所以p-1为奇数,这时就轮为上面的状态了。

所以当有多段的情况下,发现分奇数时是不会影响先手顺序的(就是说分完奇数后是不影响分下一段的)总是后手必胜,而当分完偶数时先手顺序会发生改变也就是原来的先手变成后手,原来的后手变为先手。

所以问题就变为了统计数列中有多少个偶数,偶数有奇数个时由于最后分偶数的先手会轮为一开始的先手,也就是先手必胜,反之后手必胜。

代码写的很挫。。

#include<stdio.h>#include<iostream>#include<algorithm>#include<string.h>#include<string>using namespace std;#define F(x,a,b) for (int x=a;x<=b;x++)int main(){    int n;    cin>>n;    int odd=0,even=0;    int stat=2;    F(i,1,n)    {        int a;        cin>>a;if(a==1){if(stat==1){cout<<"1"<<endl;continue;}else {cout<<"2"<<endl;continue;}}        if (a&1) odd++;else even++;        if (odd&1)if ((odd+even)%2==0) {cout<<"1"<<endl;stat=1;}else {cout<<"2"<<endl;stat=2;}        else if ((odd+even)%2==1){cout<<"1"<<endl;stat=1;}else {cout<<"2"<<endl;stat=2;}    }}


0 0
原创粉丝点击