Online Meeting CodeForces - 421C

PS:嫩是没读懂题。假设在消息记录中存在一个leader,则在任何一个log in之前他都在,换言之他没下线。或者他是在最后下线的。

//#include<bits/stdc++.h>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<bitset>
#include<vector>
#include<queue>
#include<map>
#include<string>
#include<stack>
#define ll long long
#define P pair<int, int>
#define PP pair<int,pair<int, int>>
#define pb push_back
#define pp pop_back
#define lson root << 1
#define INF (int)2e9 + 7
#define rson root << 1 | 1
#define LINF (unsigned long long int)1e18
#define mem(arry, in) memset(arry, in, sizeof(arry))
using namespace std;

inline void coutSpace() { puts("\n"); }
inline void coutInt(int x) { cout << x << endl; }
inline void coutSpaceInt(int x) { cout << x << " "; }
inline void coutLong(ll x) { cout << x << endl; }
inline void coutSpaceLong(ll x) { cout << x << " "; }
inline void printInt(int x) { printf("%d\n", x); }
inline void printLong(ll x) { printf("%lld\n", x); }
inline void printDouble(double x) { printf("%.7f\n", x); }

const int N = 1e5 + 5;

int n, m, a[N], ans[N];
char c[N];

int main()
{
    cin >> n >> m;
    for(int i = 0; i < m; i++) cin >> c[i] >> a[i];

    bool flag = false;
    int first = -1, sum = 0, cnt = 0;

    for(int i = 0; i < m; i++) {
        if(i == 0) {
            first = a[i];
            flag = true;
        }
        if(c[i] == '+') {
            if(a[i] != first && ans[first] == -1) flag = false;
            ans[a[i]] = 1;
            cnt++;
        }
        else {
            if(ans[a[i]] == 1) cnt--;
            if(a[i] != first && ans[a[i]] == 0) {
                first = a[i];
                flag = true;
            }
            if(a[i] == first && cnt) flag = false;
            ans[a[i]] = -1;
        }
    }

    if(flag) ans[first] = 0;

    for(int i = 1; i <= n; i++) if(ans[i] == 0) sum++;
    coutInt(sum);
    for(int i = 1; i <= n; i++) if(ans[i] == 0) coutSpaceInt(i);
    coutSpace();
}

 

posted @ 2018-07-29 15:58  天之道,利而不害  阅读(249)  评论(0编辑  收藏  举报