Codeforces 420 B. Online Meeting
1 second
256 megabytes
standard input
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).
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.
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.
5 4
+ 1
+ 2
- 2
- 1
4
1 3 4 5
3 2
+ 1
- 2
1
3
2 4
+ 1
- 1
+ 2
- 2
0
5 6
+ 1
- 1
- 3
+ 3
+ 4
- 4
3
2 3 5
2 4
+ 1
- 2
+ 2
- 1
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的更多相关文章
- 【codeforces 782B】The Meeting Place Cannot Be Changed
[题目链接]:http://codeforces.com/contest/782/problem/B [题意] 每个人都有一个速度,只能往上走或往下走; 然后让你找一个地方,所有人都能够在t时间内到达 ...
- Codeforces 782B:The Meeting Place Cannot Be Changed(三分搜索)
http://codeforces.com/contest/782/problem/B 题意:有n个人,每个人有一个位置和速度,现在要让这n个人都走到同一个位置,问最少需要的时间是多少. 思路:看上去 ...
- Codeforces Round #433 (Div. 2)【A、B、C、D题】
题目链接:Codeforces Round #433 (Div. 2) codeforces 854 A. Fraction[水] 题意:已知分子与分母的和,求分子小于分母的 最大的最简分数. #in ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- codeforces B. Online Meeting 解题报告
题目链接:http://codeforces.com/problemset/problem/420/B 题目意思:给出一段连续的消息记录:记录着哪些人上线或者下线.问通过给出的序列,找出可能为lead ...
随机推荐
- GNU名称解析
GNU它是GNU's NOT UNIX缩写G N U缩写,和GNU全名GNU's NOT UNIX 中间 GNU 也GNU's NOT UNIX缩写,它使用递归方式定义GNU.
- BZOJ 3747 POI2015 Kinoman 段树
标题效果:有m点,每个点都有一个权值.现在我们有这个m为点的长度n该序列,寻求区间,它仅出现一次在正确的点区间内值和最大 想了很久,甚至神标题,奔说是水的问题--我醉了 枚举左点 对于每个请求留点右键 ...
- Docker镜像与容器命令(转)
Docker是一个开源的引擎,可以轻松的为任何应用创建一个轻量级的.可移植的.自给自足的容器.开发者在笔记本上编译测试通过的容器可以批量地在生产环境中部署,包括VMs(虚拟机).bare metal. ...
- C# 几种方法来复制的阵列
突然接触到,所以就写一下共享. 首先说明一下,数组是引用类型的,所以注意不要在复制时复制了地址而没有复制数值! 事实上在复制数组的时候.一定要用new在堆中开辟一块新的空间专门用于存放数组.这样才是有 ...
- Python爬虫(一)
花了四天的时间用python写了个简单的爬虫程序.整个过程分为两个部分:工具的安装和程序的实现 本文并没有讲程序的详细实现遇到的问题,而是对着手前一些前期的准备 第一部分(工具的安装) 开发工具的下载 ...
- S如何解决安卓DK无法下载Package问题
安装一些用户Android SDK后.打开Android SDK Manager下载API当总是显示"Done loading packages"却迟迟不能前进.自己也出现了这样的 ...
- [LeetCode116]Path Sum
题目: Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up ...
- 【LeetCode】- Valid Palindrome(右回文)
[ 问题: ] Given a string, determine if it is a palindrome, considering only alphanumeric characters an ...
- 浅谈web网站架构演变过程(转)
前言 我们以javaweb为例,来搭建一个简单的电商系统,看看这个系统可以如何一步步演变. 该系统具备的功能: 用户模块:用户注册和管理 商品模块:商品展示和管理 交易模块:创建交易和管理 阶 ...
- 一切从编辑器说起:web前端代码编辑器
俗话说:工欲善其事,必先利其器. 工欲善其事必先利其器.谓工匠想要使他的工作做好,一定要先让工具锋利.比喻要做好一件事,准备工作非常重要. 前端写代码也是一样,需要一个好的适合自己的代码编辑器. 我想 ...