Codeforces Round #366 (Div. 2)

来源:互联网 发布:java轻量级web框架 编辑:程序博客网 时间:2024/05/16 06:39
A. Hulk
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Dr. Bruce Banner hates his enemies (like others don't). As we all know, he can barely talk when he turns into the incredible Hulk. That's why he asked you to help him to express his feelings.

Hulk likes the Inception so much, and like that his feelings are complicated. They haven layers. The first layer is hate, second one is love, third one is hate and so on...

For example if n = 1, then his feeling is "I hate it" or ifn = 2 it's "I hate that I love it", and ifn = 3 it's "I hate that I love that I hate it" and so on.

Please help Dr. Banner.

Input

The only line of the input contains a single integern (1 ≤ n ≤ 100) — the number of layers of love and hate.

Output

Print Dr.Banner's feeling in one line.

Examples
Input
1
Output
I hate it
Input
2
Output
I hate that I love it
Input
3
Output
I hate that I love that I hate it
题意:看样例输出就可以了。
代码:
    #include <cstdio>    #include <cstdlib>    #include <cstring>    #include <iostream>    #include <cmath>    #include <set>    #include <map>    #include <vector>    #include <algorithm>    #define LL long long    #define lson l,m,rt<<1    #define rson m+1,r,rt<<1|1    #define maxn 1000010    using namespace std;    int t,n,m,i,j,x,y;    LL a[maxn],b[maxn];    int main()    {        scanf("%d",&t);       // memset(a,0,sizeof(a));        //memset(b,0,sizeof(b));        int ans=0;        int sum=0;        if(t==1)        {            cout<<"I hate it"<<endl;            return 0;        }        for(int i=1;i<=t;i++)        {            if(i%2==1)            {                if(i==t)                {                    cout<<" I hate it"<<endl;                }                else                {                if(ans==0)                printf("I hate that");                else                    printf(" I hate that");                    ans++;                }            }            else            {                if(i==t)                    cout<<" I love it"<<endl;                    else                    {                    printf(" I love that");                    }            }        }
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 exactlyvi vertices. Players play alternatively. Peter goes first. On each turn a player must choose a cycle with at least2 vertices (for example,x vertices) among all available cycles and replace it by two cycles withp andx - p vertices where1 ≤ 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 withai 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 integern (1 ≤ n ≤ 100 000) — the number of tests Peter is about to make.

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

Output

Print the result of all tests in order they are performed. Print1 if the player who moves first wins or2 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 with1 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 with1 vertex. First player can replace the second cycle with two cycles of1 vertex and second player can't make any move and loses.

In his third test, cycles have 1, 2 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 size1 and one with size 2. Now cycles have1,1, 2, 2 vertices. Second player's only move is to replace a cycle of size2 with2 cycles of size1. And cycles are1, 1, 1, 1, 2. First player replaces the last cycle with2 cycles with size1 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 sizes1 and4 or 2 and 3.

  • If he replaces it with cycles of sizes 1 and 4: Only second cycle matters. Second player will replace it with2 cycles of sizes2. First player's only option to replace one of them with two cycles of size1. 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 size3 with two of sizes1 and2. Now only cycles with more than one vertex are two cycles of size2. As shown in previous case, with2 cycles of size 2 second player wins.

So, either way first player loses.

题意:
两个人进行n轮比赛,每轮在数列中取前n个数,游戏的规则是,每次把一个数拆成两个正整数和,直到不能拆为止,如果先手赢,输出 1,否则输出2.

题解:

对于每个数ai,最多能拆ai-1次,判断ai-1的奇偶姓,前缀和判断即可。

代码:

    #include <cstdio>    #include <cstdlib>    #include <cstring>    #include <iostream>    #include <cmath>    #include <set>    #include <map>    #include <vector>    #include <algorithm>    #define LL long long    #define lson l,m,rt<<1    #define rson m+1,r,rt<<1|1    #define maxn 1000010    using namespace std;    int t,n,m,i,j,x,y;    LL a[maxn],b[maxn];    int main()    {        scanf("%d",&t);        memset(a,0,sizeof(a));        memset(b,0,sizeof(b));        for(int i=0;i<t;i++)        {            scanf("%I64d",&a[i]);            a[i]--;            a[i]=a[i]%2;        }        b[0]=a[0];        for(i=1;i<t;i++)        {          b[i]=b[i-1]+a[i];        }        for(int i=0;i<t;i++)        {            if(b[i]%2==1)                a[i]=1;            else                a[i]=2;        }        for(int i=0;i<t;i++)        {            printf("%I64d\n",a[i]);        }    }

C:

C. Thor
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Thor is getting used to the Earth. As a gift Loki gave him a smartphone. There aren applications on this phone. Thor is fascinated by this phone. He has only one minor issue: he can't count the number of unread notifications generated by those applications (maybe Loki put a curse on it so he can't).

q events are about to happen (in chronological order). They are of three types:

  1. Application x generates a notification (this new notification is unread).
  2. Thor reads all notifications generated so far by applicationx (he may re-read some notifications).
  3. Thor reads the first t notifications generated by phone applications (notifications generated in firstt events of the first type). It's guaranteed that there were at leastt events of the first type before this event. Please note that he doesn't read firstt unread notifications, he just reads the very firstt notifications generated on his phone and he may re-read some of them in this operation.

Please help Thor and tell him the number of unread notifications after each event. You may assume that initially there are no notifications in the phone.

Input

The first line of input contains two integers n andq (1 ≤ n, q ≤ 300 000) — the number of applications and the number of events to happen.

The next q lines contain the events. Thei-th of these lines starts with an integertypei — type of thei-th event. If typei = 1 ortypei = 2 then it is followed by an integerxi. Otherwise it is followed by an integerti (1 ≤ typei ≤ 3, 1 ≤ xi ≤ n, 1 ≤ ti ≤ q).

Output

Print the number of unread notifications after each event.

Examples
Input
3 41 31 11 22 3
Output
1232
Input
4 61 21 41 23 31 31 3
Output
123012
Note

In the first sample:

  1. Application 3 generates a notification (there is1 unread notification).
  2. Application 1 generates a notification (there are2 unread notifications).
  3. Application 2 generates a notification (there are3 unread notifications).
  4. Thor reads the notification generated by application3, there are2 unread notifications left.

In the second sample test:

  1. Application 2 generates a notification (there is1 unread notification).
  2. Application 4 generates a notification (there are2 unread notifications).
  3. Application 2 generates a notification (there are3 unread notifications).
  4. Thor reads first three notifications and since there are only three of them so far, there will be no unread notification left.
  5. Application 3 generates a notification (there is1 unread notification).
  6. Application 3 generates a notification (there are2 unread notifications).


题意:

一部手机有n个软件,q个操作。

操作1:编号为y的软件产生一个未读信息。

操作2:读完编号为y的软件产生的所有信息。

操作3:读完从1开始的前y个信息。

注意:可能重复读已经读过的信息。

问每次操作后,还有多少未读信息?

题解:

容器 set的使用,1操作往编号为y的set里加入一个一个元素i(我们把每个信息由1开始编号)。2操作求出编号为y的set的大小。清空。3操作,由l到y,看记录这个信息的set里是否还有这个信息,有答案-1,并把这个信息从set里删除。然后左端点l=max(l,y+1)。

代码:

#include <cstdio>#include <cstdlib>#include <cstring>#include <iostream>#include <cmath>#include <set>#include <map>#include <vector>#include <queue>#include <algorithm>#define LL long long#define lson l,m,rt<<1#define rson m+1,r,rt<<1|1#define maxn 300100using namespace std;int n,q,x,y;set<int>a[maxn];int b[maxn];int l=1;int main(){    scanf("%d%d",&n,&q);    int ans=0;    int mx;    int flag=1;    while(q--)    {        scanf("%d%d",&x,&y);        if(x==1)        {            ans++;            a[y].insert(flag);            b[flag]=y;            flag++;        }        else if(x==2)        {            ans-=a[y].size();            a[y].clear();        }        else        {            for(int i=l; i<=y; i++)            {                if(a[b[i]].count(i))                {                    ans--;                    a[b[i]].erase(i);                }            }            l=max(l,y+1);        }        printf("%d\n",ans);    }}



0 0