一道实现很蛋疼的题。必须静下理清思路,整理出各种情况。不然就会痛苦地陷入一大堆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. Swagger+Spring mvc生成Restful接口文档

    简介 Swagger 是一个规范和完整的框架,用于生成.描述.调用和可视化 RESTful 风格的 Web 服务.总体目标是使客户端和文件系统作为服务器以同样的速度来更新.文件的方法,参数和模型紧密集 ...

  2. TIOBE Index for December 2015(转载)

    There is hardly any doubt about it, Java will become TIOBE's programming language of the year 2015. ...

  3. HTC Vive开发笔记之手柄震动

    手柄震动的代码SteamVR_Controller脚本的最上面的注释里面就有说明,其实也很简单 // Example usage: //这个栗子是左手柄震动 右手震动只需把Leftmost换成Righ ...

  4. 1.date 命令

    转自:http://www.cnblogs.com/peida/archive/2012/12/13/2815687.html 在linux环境中,不管是编程还是其他维护,时间是必不可少的,也经常会用 ...

  5. Oracle时间戳 与时间之间的相互转换

    Unix时间戳记是从'1970-01-01 00:00:00'GMT开始的秒数,表现为整数型. Oracle中的时间是Date型,以下函数提供了两种时间转换的Oracle函数 (1)从Unix时间戳记 ...

  6. 70. Implement strStr() 与 KMP算法

    Implement strStr() Implement strStr(). Returns a pointer to the first occurrence of needle in haysta ...

  7. 多个字段用and和or时要注意用括号。

    多个字段用and和or时要注意用括号. 新技能get! create table wly_test (name1 varchar2(10),number1 number(6),score1 numbe ...

  8. SQLite数据库文件格式

    数据库命名约定 sqlite3_open()API用到数据库的文件名,可以是相对当前工作目录的相对路径名,也可以是从系统根文件树开始的完整路径名.任何被本地文件系统接受的正规文件名都是好的. 如果文件 ...

  9. winform.布局

    布局:默认布局:自己拖动进行布局,工具栏里对齐方式 右键,锁定.##随容器拉动变化属性:Anchor:上下左右,固定的设置 panel的排列 1.Dock属性:(顺序填充)Top:靠上,高度不变,左右 ...

  10. 多媒体(4):JPEG图像压缩编码

    (重要的事放前面)此JPEG的C++实现见 https://github.com/chencjGene/SoftEngineering/tree/master/JPEG 目录 多媒体(1):MCI接口 ...