一道实现很蛋疼的题。必须静下理清思路,整理出各种情况。不然就会痛苦地陷入一大堆if..else里不能自拔。

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<sstream>
#include<cmath>
#include<climits>
#include<string>
#include<map>
#include<queue>
#include<vector>
#include<stack>
#include<set>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
#define pb(a) push(a)
#define INF 0x1f1f1f1f
#define lson idx<<1,l,mid
#define rson idx<<1|1,mid+1,r
#define PI 3.1415926535898
template<class T> T min(const T& a,const T& b,const T& c) {
return min(min(a,b),min(a,c));
}
template<class T> T max(const T& a,const T& b,const T& c) {
return max(max(a,b),max(a,c));
}
void debug() {
#ifdef ONLINE_JUDGE
#else freopen("in.txt","r",stdin);
freopen("d:\\out1.txt","w",stdout);
#endif
}
int getch() {
int ch;
while((ch=getchar())!=EOF) {
if(ch!=' '&&ch!='\n')return ch;
}
return EOF;
} const int maxn = 1e5+;
bool canbe[maxn];
int canbeset[maxn];
int first[maxn];
char op[maxn];
int id[maxn];
int main()
{
int n,m;
scanf("%d%d", &n, &m);
for(int i = ; i <= m; i++ )
{
op[i] = getch();
scanf("%d", &id[i]);
if( first[id[i]] == )
first[id[i]] = op[i] == '+' ? : -; }
int cnt=;
int sz=;
for(int i=;i<=n;i++)
{
if(first[i]==-)
cnt++;
if(first[i]==)
canbeset[sz++]=i;
} for(int i=;i<=n;i++) canbe[i] = true;
if(cnt>) for(int i=;i<=n;i++)
if(first[i]==) canbe[canbeset[--sz]] = false; for(int i=;i<=m;i++)
{
if(op[i]=='+')
{
if(cnt>) canbe[id[i]]=;
cnt++;
while(sz)
{
sz--;
if(canbeset[sz]!=id[i]) canbe[canbeset[sz]]=;
}
}else
{
cnt--;
if(cnt>) canbe[id[i]]=;
if(canbe[id[i]]) canbeset[sz++]=id[i];
}
}
sz=;
for(int i=;i<=n;i++)
if(canbe[i])
canbeset[sz++]=i;
printf("%d\n",sz);
for(int i=;i<sz;i++)
printf("%d%c",canbeset[i],i==sz-?'\n':' '); return ;
}

codeforces 420B Online Meeting的更多相关文章

  1. Online Meeting CodeForces - 420B (思维)

    大意: 给定某一段连续的上线下线记录, 老板上线或下线时房间无人, 并且每次会议都在场, 求哪些人可能是老板. 结论1: 从未出现过的人一定可以是老板. 结论2: 出现过的人中老板最多只有1个. 结论 ...

  2. 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 ...

  3. Codeforces 782B The Meeting Place Cannot Be Changed(二分答案)

    题目链接 The Meeting Place Cannot Be Changed 二分答案即可. check的时候先算出每个点可到达的范围的区间,然后求并集.判断一下是否满足l <= r就好了. ...

  4. CF - 420B - Online Meeting(思维)

    题意:n 个人參加线上会议.某经理记录了中间一段时间的 m 条上下线记录(1 ≤ n, m ≤ 105).+ 表示上线,- 表示下线. leader是指仅仅要有人在线,他都在线的人.求全部可能的lea ...

  5. codeforces B. Online Meeting 解题报告

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

  6. codeforces 782B The Meeting Place Cannot Be Changed+hdu 4355+hdu 2438 (三分)

                                                                   B. The Meeting Place Cannot Be Change ...

  7. Codeforces 853B Jury Meeting (差分+前缀和)

    <题目链接> 题目大意: 有$ n(n<=1e5)$个城市和一个首都(0号城市),现在每个城市有一个人,总共有$ m (m<=1e5)$次航班,每个航班要么从首都起飞,要么飞到 ...

  8. codeforces 782B - The Meeting Place Cannot Be Changed

    time limit per test 5 seconds memory limit per test 256 megabytes input standard input output standa ...

  9. codeforces 853b//Jury Meeting// Codeforces Round #433 (Div. 1)

    题意:几个人要去一个城市k天,现给出各航班的日期和花费,让这n个人能相会k天的最小花费? 用数组arr1[i]记录在第i天人到齐的最小花费.arr2[i]记录第i天之后才有人开始走的最小花费.然后取a ...

随机推荐

  1. jQuery入门级part.1

    jquery的选择器: 基本选择器: #id               根据id的属性值来获取元素 TagName     根据标签名来获取元素 selector1,selector2   匹配列表 ...

  2. PHP远程下载图片损坏问题

    代码如下: <?php header("Content-type=html/text;charset=utf-8"); function download($file_nam ...

  3. Asp.net MVC中 Controller 与 View之间的数据传递

    在ASP.NET MVC中,经常会在Controller与View之间传递数据 1.Controller向View中传递数据 (1)使用ViewData["user"] (2)使用 ...

  4. silverlight列表控件ComboBox 托管代码绑订数据集合

    .xaml <ComboBox x:Name="myCombobox" Width="300" Height="30"> < ...

  5. LeetCode Implement pow(x, n).

    这个题目我也没有思路,同学们可以查看这个http://www.cnblogs.com/NickyYe/p/4442867.html 下面是我改进后的代码 第一种方法: class Solution { ...

  6. Django TemplateView

    主要功能是渲染模板,看官例: from django.views.generic.base import TemplateView from articles.models import Articl ...

  7. 刷了OpenWrt Attitude Adjustment 12.09,很满意

    OpenWrt的这个新版本编译好的固件里集成了luci,图形界面还是很方便的. 装了wpad.qos之后,空间刚好剩下一点点,囧,4M闪存还是不够折腾啊. 发现一个bug:如果空间不够的情况下继续安装 ...

  8. bash操作小结

    刚开始学写bash脚本,发现有很多需要注意的细节问题,在这里记录一下便于记忆: 1. help test  帮助 2. bash提供的数组数据结构,它是以数字为下标的,和C语言从0开始的下一样  参考 ...

  9. SQL笔记-第七章,表连接

    SQL中使用JOIN 关键字来使用表连接.表连接有多种不同的类型,被主流数据库系统支持的有交叉连接(CROSS JOIN).内连接(INNER JOIN).外连接(OUTTER JOIN),另外在有的 ...

  10. awk用法

    目前虽然有很多工具可以代替awk,但是呢我还是认为awk还是非常重要,比如有时候load数据到hive,mysql发现数据有点问题,这样可以先对比文件和库中数据是否一致,这样awk就发挥用处了,还有从 ...