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. Scripting Java #3:Groovy与invokedynamic

    只需看看今天Groovy语言实现机制.在此之前,是第一个推倒静态类型与动态类型语言在实现上面的一些差异. 静态类型 vs. 动态类型 看以下这个简单的栗子. def addtwo(a, b) { re ...

  2. DOMContentLoaded和window.onload

    相信写js的.都知道window.onload吧,可是并非每一个人都知道DOMContentLoaded,事实上即使你不知道.非常有可能你也常常使用了这个东西. 普通情况下,DOMContentLoa ...

  3. js+html+css简单的互动功能页面(2015知道几乎尖笔试题)http://v.youku.com/v_show/id_XMTI0ODQ5NTAyOA==.html?from=y1.7-1.2

    js+html+css实现简单页面交互功能(2015知乎前端笔试题) http://v.youku.com/v_show/id_XMTI0ODQ5NTAyOA==.html? from=y1.7-1. ...

  4. [转载] 树莓派读取温湿度传感器DHT11

    原文地址: http://blog.csdn.net/liang890319/article/details/8739683 硬件: 树莓派 2.0 DHT模块  接树莓派5V GND GPIO1 功 ...

  5. Oracle如何插入在特殊字符: &amp; 和 &#39; (各种解决方案)

    分类: Oracle Oracle中怎样插入特殊字符:& 和 ' (多种解决方式) 今天在导入一批数据到Oracle时,碰到了一个问题:Toad提示要给一个自己定义变量AMP赋值,一開始我非常 ...

  6. Cocos发展Visual Studio下一个libcurl图书馆开发环境的搭建

    我们解释win32在Visual Studio下一个libcurl图书馆开发环境的搭建.Cocos2d-x发动机实际上与Win32在访问libcurl库.Cocos2d-x 3.x在libcurl库文 ...

  7. cocos2d-x路~使得第一个字游戏(一个)

    前言 去年的回忆.另外,在第三.他们开发了他们的第一场比赛四月,它是游戏.所以我决定走上独立开发的道路上.了.第一款游戏达到它应有的盈利水平.然而这款游戏开发后的时间里.都没再取得还有一款令自己惬意的 ...

  8. [LeetCode299]Bulls and Cows

    题目: You are playing the following Bulls and Cows game with your friend: You write down a number and ...

  9. 小代码编写神器:LINQPad 使用入门

    原文:小代码编写神器:LINQPad 使用入门 一:概述 1:想查看程序运行结果,又不想启动 VS 怎么办? 2:想测试下自己的 C# 能力,不使用 VS 的智能感知,怎么办? 那么,我们有一个选择, ...

  10. Python调用微博API

    上头叫通过微博ID获取用户公布过的历史微博内容,于是研究了下新浪微博提供的API 1 首先在微博开放中心下"创建应用"创建一个应用,应用信息那些随便填,填写完成后,不须要提交审核, ...