• loj 6085.「美团 CodeM 资格赛」优惠券


    题目:

    一个有门禁的大楼,初始时里面没有人。
    现在有一些人在进出大楼,每个人都有一个唯一的编号。现在有他们进出大楼的记录,但是有些被污染了,只能知道这里有一条记录,具体并不能知道。
    一个人只有进大楼,才能出大楼,如果在大楼内,他必须先出去,才能再进来。
    现在想知道这个记录是否错误,如果错误,请求出最早的错误在哪一行。
    注释:人有无穷多个,记录中没有提到的人也可以进出大楼。

    题解:

    SB 题

    #include <set>
    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    using namespace std;
    typedef long long ll;
    inline void read(int &x){
        x=0;static char ch;static bool flag;flag = false;
        while(ch=getchar(),ch<'!');if(ch == '-') ch=getchar(),flag = true;
        while(x=10*x+ch-'0',ch=getchar(),ch>'!');if(flag) x=-x;
    }
    #define rg register int
    #define rep(i,a,b) for(rg i=(a);i<=(b);++i)
    #define per(i,a,b) for(rg i=(a);i>=(b);--i)
    const int maxn = 500010;
    set<int>s;
    bool exist[maxn];
    int last[maxn];
    int main(){
        int n;read(n);
        char ch;int x;
        int ans = -1;
        rep(i,1,n){
            while(ch=getchar(),ch<'!');
            if(ch == '?') s.insert(i);
            else{
                read(x);
                if(ch == 'I'){
                    if(exist[x]){
                        set<int>::iterator it = s.lower_bound(last[x]);
                        if(it == s.end()){ans = i;break;}
                        else s.erase(it);
                    }exist[x] = true;
                }else{
                    if(!exist[x]){
                        set<int>::iterator it = s.lower_bound(last[x]);
                        if(it == s.end()){ans = i;break;}
                        else s.erase(it);
                    }exist[x] = false;
                }
                last[x] = i;
            }
        }
        printf("%d
    ",ans);
        return 0;
    }
    
  • 相关阅读:
    (转)SQL Server 2005两种安全验证模式
    C#练习题记录(交换两个数1)
    C# using 用法
    服务器的理解(菜鸟)
    zZ
    ZzZ
    [转]Arcgis制作泰森多边形具体步骤
    [转]免费网站推广
    [转]如何让Firefox优化得比Chrome更快
    [转]3天搞定网站重新被百度收录的方法
  • 原文地址:https://www.cnblogs.com/Skyminer/p/7077636.html
Copyright © 2020-2023  润新知