Codeforces 420 B. Online Meeting
2015-12-09 20:31
375 查看
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
output
input
output
input
output
input
output
input
output
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; }
相关文章推荐
- leetcode Path Sum II
- Android 读取txt文件并以utf-8格式转换成字符串
- 欢迎使用CSDN-markdown编辑器
- POJ 3252 Round Numbersm
- ubuntu下gerrit 安装部署
- sap JCO3.0安装缺少Microsoft Visual C++ 2005 Service Pack 1 Redistributable Package (KB973544)
- 106 Construct Binary Tree from Inorder and Postorder Traversal
- leetcode Flatten Binary Tree to Linked List
- gdb使用指南:单步执行和跟踪函数调用
- 谈WinDbg之InternalCall的使用与实现
- java 的 gc 垃圾回收机制
- 盘点:让世界眼前一亮 习近平“中国范”的抵达
- VirtualBox 创建的 Mac OS X 虚拟机换主机后不能启动问题
- 网站压力测试工具Webbench介绍
- 给 ecplise 配置struts2配置环境
- 在Web应用中接入微信支付的流程之极简清晰版
- JavaEE_增删查改的思路
- Git 分支管理和冲突解决
- android View简介
- uboot网卡移植