zoukankan      html  css  js  c++  java
  • 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;
    }
    
  • 相关阅读:
    iOS开发-ScrollView图片缩放
    算法-随机不重复数列生成
    iOS开发-舒尔特表
    iOS开发-音乐播放
    iOS开发-简单的图片查看器
    iOS开发-Interface Builder的前世今生
    iOS开发-DatePicker控件
    iOS开发-UI基础Demo
    Objective-C-Category类别
    Objective-C面向对象之实现类
  • 原文地址:https://www.cnblogs.com/Skyminer/p/7077636.html
Copyright © 2011-2022 走看看