Coder-Strike 2014 - Finals (online edition, Div. 2) Online Meeting

Nearly each project of the F company has a whole team of developers working on it. They often are in different rooms of the office in different cities and even countries. To keep in touch and track the results of the project, the F company conducts shared online meetings in a Spyke chat.

One day the director of the F company got hold of the records of a part of an online meeting of one successful team. The director watched the record and wanted to talk to the team leader. But how can he tell who the leader is? The director logically supposed that the leader is the person who is present at any conversation during a chat meeting. In other words, if at some moment of time at least one person is present on the meeting, then the leader is present on the meeting.

You are the assistant director. Given the 'user logged on'/'user logged off' messages of the meeting in the chronological order, help the director determine who can be the leader. Note that the director has the record of only a continuous part of the meeting (probably, it's not the whole meeting).

Input

The first line contains integers n and m (1 ≤ n, m ≤ 105) — the number of team participants and the number of messages. Each of the next m lines contains a message in the format:

  • '+ id': the record means that the person with number id (1 ≤ id ≤ n) has logged on to the meeting.
  • '- id': the record means that the person with number id (1 ≤ id ≤ n) has logged off from the meeting.

Assume that all the people of the team are numbered from 1 to n and the messages are given in the chronological order. It is guaranteed that the given sequence is the correct record of a continuous part of the meeting. It is guaranteed that no two log on/log off events occurred simultaneously.

Output

In the first line print integer k (0 ≤ k ≤ n) — how many people can be leaders. In the next line, print k integers in the increasing order — the numbers of the people who can be leaders.

If the data is such that no member of the team can be a leader, print a single number 0.

Sample test(s)
Input
5 4
+ 1
+ 2
- 2
- 1
Output
4
1 3 4 5 
Input
3 2
+ 1
- 2
Output
1
3 
Input
2 4
+ 1
- 1
+ 2
- 2
Output
0
Input
5 6
+ 1
- 1
- 3
+ 3
+ 4
- 4
Output
3
2 3 5 
Input
2 4
+ 1
- 2
+ 2
- 1
Output
0

题意: 题目要求找到可能的 leader, 冲要条件是会议有人在时他必须在...还应该注意的一点是,如果网上只有 leader 时 他可上可下;

思路: 读懂了题目, 不知道怎么实现, 问了静姐才知道...

         题目直接找到可能的leader 十分困难, 应该从反面入手 计算不可能成为leader 的人;

CODE:

#include<stdio.h>
#include<iostream>
#include<string.h>
#include<set>
using namespace std;
int n,m;
struct M
{
    char x;
    int id;
    void init()
    {
        scanf("%s%d",&x,&id);
    }
}a[100010];
set<int>que;
bool no[100010],vis[100010];
int ans[100010];
int main()
{
    while(~scanf("%d%d",&n,&m))
    {
        memset(no,0,sizeof(no));
        memset(vis,0,sizeof(vis));
        for(int i=1;i<=m;i++)
        {
            a[i].init();
            if(a[i].x=='+'&&vis[a[i].id]==0) vis[a[i].id]=1;
            else if(a[i].x=='-'&&vis[a[i].id]==0) que.insert(a[i].id);
        }

        int mb=-1;
        for(int i=1;i<=m;i++)
        {
            if(a[i].x=='-')
            {
                if(que.size()>1) no[a[i].id]=1;
                else if(que.size()==1) mb=a[i].id;
                que.erase(a[i].id);
            }
            else if(a[i].x=='+')
            {
                if(que.size()!=0) no[a[i].id]=1;
                else if(mb!=-1&&a[i].id!=mb)
                {
                    no[mb]=1,no[a[i].id]=1;
                }
                que.insert(a[i].id);
            }
        }
        int len=0;
        for(int i=1;i<=n;i++)
        {
            if(no[i]==0) ans[len++]=i;
        }
        printf("%d\n",len);
        if(len!=0)
        {
            for(int i=0;i<len-1;i++)
                printf("%d ",ans[i]);
            printf("%d",ans[len-1]);
        }
    }
    return 0;
}


        

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值