一道实现很蛋疼的题。必须静下理清思路,整理出各种情况。不然就会痛苦地陷入一大堆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. Spring学习 Ioc篇(二 )

    5.spring依赖注入的方式 方法一:使用构造器方式进行注入 1.dao的类和接口 package com.cvicse.dao.impl; import com.cvicse.dao.Person ...

  2. 阿里 classloader

    http://blog.csdn.net/scythe666/article/details/51956047

  3. IIS部署WCF

    IIS部署WCF [转载自——http://www.cnblogs.com/starksoft/p/4992059.html] 1 部署IIS 1.1 安装WAS IIS原本是不支持非HTTP协议的服 ...

  4. AIR call dll

    commandproxy C#通讯 https://code.google.com/p/commandproxy smartrcp Java And Flex Application http://s ...

  5. android 图片进度条

    png图片 代码 ImageView loading=getActivity().findViewById(R.id.pro_loading); LinearInterpolator lin = ne ...

  6. Git服务器、http协议及XCode

    本来费了老鼻子牛劲搭好了SVN,可以通过web进行访问,也弄好了eclipse和XCode,结果几个开发的同事说要上git,悲了个催,又开始折腾git. 因为公司只有一个公网的http出口,因此开始了 ...

  7. POS管理系统之新增设备入库

    <%@ page language="java" import="java.util.*" pageEncoding="utf-8"% ...

  8. 防止SQL注入攻击的一些方法小结

    SQL注入攻击的危害性很大.在讲解其防止办法之前,数据库管理员有必要先了解一下其攻击的原理.这有利于管理员采取有针对性的防治措施. 一. SQL注入攻击的简单示例. statement := &quo ...

  9. Linux下编译带x264的ffmpeg的配置方法,包含SDL2

    一.环境准备 ffmpeg下载:http://www.ffmpeg.org/download.html x264下载:http://download.videolan.org/x264/snapsho ...

  10. tomacat启动慢

    tomcat目录下有多个工程,tomcat每次启动的时候都会去加载,删除不需要的工程,