B. Online Meeting
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

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

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <set> using namespace std; const int maxn=110000; set<int> chat,st;
bool vis[maxn];
int id[maxn];
char op[maxn]; int main()
{
int n,m;
scanf("%d%d",&n,&m);
for(int i=0;i<m;i++)
{
getchar();
scanf("%c%d",op+i,id+i);
}
for(int i=0;i<m;i++)
{
if(op[i]=='-')
{
if(vis[id[i]]==false)
chat.insert(id[i]);
}
vis[id[i]]=true;
}
memset(vis,0,sizeof(vis));
for(int i=0;i<m;i++)
{
if(op[i]=='+')
{
if(chat.size()>0) vis[id[i]]=true;
else st.insert(id[i]);
chat.insert(id[i]);
}
else if(op[i]=='-')
{
if(chat.size()>1) vis[id[i]]=true;
else st.insert(id[i]);
chat.erase(id[i]);
}
}
if(st.size()>1)
{
set<int>::iterator it;
for(it=st.begin();it!=st.end();it++)
{
vis[*it]=true;
}
}
int cnt=0;
for(int i=1;i<=n;i++) if(vis[i]) cnt++;
printf("%d\n",n-cnt);
for(int i=1;i<=n;i++)
if(!vis[i]) printf("%d ",i);
putchar(10);
return 0;
}

Codeforces 420 B. Online Meeting的更多相关文章

  1. 【codeforces 782B】The Meeting Place Cannot Be Changed

    [题目链接]:http://codeforces.com/contest/782/problem/B [题意] 每个人都有一个速度,只能往上走或往下走; 然后让你找一个地方,所有人都能够在t时间内到达 ...

  2. Codeforces 782B:The Meeting Place Cannot Be Changed(三分搜索)

    http://codeforces.com/contest/782/problem/B 题意:有n个人,每个人有一个位置和速度,现在要让这n个人都走到同一个位置,问最少需要的时间是多少. 思路:看上去 ...

  3. Codeforces Round #433 (Div. 2)【A、B、C、D题】

    题目链接:Codeforces Round #433 (Div. 2) codeforces 854 A. Fraction[水] 题意:已知分子与分母的和,求分子小于分母的 最大的最简分数. #in ...

  4. codeforces 782B The Meeting Place Cannot Be Changed (三分)

    The Meeting Place Cannot Be Changed Problem Description The main road in Bytecity is a straight line ...

  5. Codeforces 714A Meeting of Old Friends

    A. Meeting of Old Friends time limit per test:1 second memory limit per test:256 megabytes input:sta ...

  6. Codeforces Round #375 (Div. 2) A. The New Year: Meeting Friends 水题

    A. The New Year: Meeting Friends 题目连接: http://codeforces.com/contest/723/problem/A Description There ...

  7. Codeforces Round #371 (Div. 2) A. Meeting of Old Friends 水题

    A. Meeting of Old Friends 题目连接: http://codeforces.com/contest/714/problem/A Description Today an out ...

  8. Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals) B. The Meeting Place Cannot Be Changed

    地址:http://codeforces.com/contest/782/problem/B 题目: B. The Meeting Place Cannot Be Changed time limit ...

  9. codeforces B. Online Meeting 解题报告

    题目链接:http://codeforces.com/problemset/problem/420/B 题目意思:给出一段连续的消息记录:记录着哪些人上线或者下线.问通过给出的序列,找出可能为lead ...

随机推荐

  1. android 项目中设置背景图片

    xml文件设置背景图片中:任意一个控件,button imageView 或layout,在其的xml属性设置中,添加 [XML] view plaincopy android:background= ...

  2. 【从翻译mos文章】rac数据库,HC_&lt;SID&gt;.dat其他文件Oracle_Home用例下。

    rac数据库.HC_<SID>.dat其他文件Oracle_Home用例下. 参考原始: RAC database HC_<SID>.dat is used by instan ...

  3. shell文字过滤程序(十):cut命令

    [版权声明:转载请保留源:blog.csdn.net/gentleliu.Mail:shallnew at 163 dot com] cut指挥类似至awk,从行内提取的信息,它是一个较弱的版本的功能 ...

  4. 2014在辛星Javascript口译科

    ***************概要*************** 1.Javascript是一种原型化继承的基于对象的动态类型的脚本语言,它区分大写和小写.主要执行在client,用户即使响应用户的操 ...

  5. 乐在其中设计模式(C#) - 适配器模式(Adapter Pattern)

    原文:乐在其中设计模式(C#) - 适配器模式(Adapter Pattern) [索引页][源码下载] 乐在其中设计模式(C#) - 适配器模式(Adapter Pattern) 作者:webabc ...

  6. 使用MySQL Workbench建立数据库,建立新的表,向表中添加数据

    使用MySQL Workbench建立数据库,建立新的表,向表中添加数据 初学数据库,记录一下所学的知识.我用的MySQL数据库,使用MySQL Workbench管理.下面简单介绍一下如何使用MyS ...

  7. Libgdx Box2D现实------这缓释微丸(一个:项目介绍)

    它花了两个星期的假写物理游戏,在几次课逃逸,是大学,因为大部分时间点!今天,我基本上一直每节课的点1-3有时它,哎,这似乎是不再逃跑.不知道值没有值得,仅仅是简单地想做自己喜欢的事情,而不是跟老师大眼 ...

  8. System.Threading.ThreadStateException

    异常:"System.Threading.ThreadStateException"在未处理的异常类型 System.Windows.Forms.dll 发生 其它信息: 在能够调 ...

  9. 学习pthreads,创建和终止多线程

    更CPU多线程编程,通过笔者的研究发现,,pthreads使用日趋广泛.它是螺纹POSIX标准,它定义了一组线程的创建和操作API. 配置环境见上博客文章.配置环境后,只需要加入#include &l ...

  10. WORD中怎样自己主动生成文件夹?

    步骤: 1.输入当做标题的文字 2.将文字设置为标题样式 3.光标放在要加入�文件夹的位置 4.选择插入->引用->索引和文件夹->文件夹->确定