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 游戏开发 View框架

    按键盘的上下键矩形就会上下移动: 通过实例化Handler对象并重写handkeMessage方法实现了一个消息接收器.然后再线程中通过sendMessage方法发送更新界面的消息,接收器收到更新界面 ...

  2. HDU 2063 过山车 二分图题解

    一个男女搭配的关系图,看能够凑成多少对,基本和最原始的一个二分图谜题一样了,就是 一个岛上能够凑成多少对夫妻的问题. 所以是典型的二分图问题. 使用匈牙利算法,写成两个函数,就很清晰了. 本程序还带分 ...

  3. java实现大数相加问题

    闲来没事.写了个acm中常常遇到的大数加减问题的java 解决代码,我想说.用java的BigInteger 非常easy. 大爱java!! 比如: 实现多组输入的大数加减问题: import ja ...

  4. 写一个程序,乞讨1+2*2+3*3+n*n值 Java

    public static void main(String[] args) {         // 1*1+2*2+3*3+n*n         int n = 40;         // 1 ...

  5. android存储阵列数据SharedPreferences

    假设要数组数据(如boolean[] .int[]等)到SharedPreferences时,我们能够先将数组数据组织成json数据存储到SharedPreferences,读取时则对json数据进行 ...

  6. uva133 The Dole Queue ( 约瑟夫环的模拟)

    题目链接: 啊哈哈,选我选我 思路是: 相当于模拟约瑟夫环,仅仅只是是从顺逆时针同一时候进行的,然后就是顺逆时针走能够编写一个函数,仅仅只是是走的方向的标志变量相反..还有就是为了(pos+flag+ ...

  7. iOS发展- backBarButtonItem 颜色/文字修改

    iOS7之后. 默认返回button字体颜色为蓝色, 在父母的陈列柜VC(老界面)的title 假设做出改变, 通过下面的方法可以: 1. 更改字体颜色 (1) 在plist里面, 加View con ...

  8. 开源Math.NET基础数学类库使用(13)C#实现其他随机数生成器

    原文:[原创]开源Math.NET基础数学类库使用(13)C#实现其他随机数生成器                本博客所有文章分类的总目录:http://www.cnblogs.com/asxiny ...

  9. Makefile 中:= ?= += =的差别 和条件运行

    一:在Makefile中常常看到obj-m    := scull.o和KERNELDIR ?= /lib/modules/等不同的赋值方式,如今总结他们的差别: = 是最主要的赋值 := 是覆盖之前 ...

  10. Attribute(两)——定义自己的特色+Asp.net MVC中间filter详细解释

    部分博客是预先定义的有关特性的一些基本特征,同时还Attribute这一概念的一个宏观上的认识,在上篇博客结尾介绍了有关为自己定义特性服务的AttributeUsage,这篇博客主要是通过filter ...