zoukankan      html  css  js  c++  java
  • Codeforces 1018D D. Order book

    解法:用l,r分别代表buy的最大值和sell的最小值,add时,若添加的值在l,r之间,则该值有可能作为下一次accept的值

    accept x时,x只能在区间[l,r]中,否则无解,若x为l或r,ans不变,否则,x的类型可以是sell或buy,ans*=2,更新l,r值为x的左右值

    结尾是add而没有accept时,需要维护出现在l,r之间的值得数量,这些值可以是buy或sell,ans*=(ins+1)即可

    (结尾*=(ins+1)想成了+=(ins+1),记录一下自己犯的小错误,小错误最烦人)

    #include<iostream>
    #include<cstdio> 
    #include<cmath>
    #include<queue>
    #include<vector>
    #include<string.h>
    #include<cstring>
    #include<algorithm>
    #include<set>
    #include<map>
    #include<fstream>
    #include<cstdlib>
    #include<ctime>
    #include<list>
    #include<climits>
    #include<bitset>
    using namespace std;
    #define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    #define fopen freopen("input.in", "r", stdin);freopen("output.in", "w", stdout);
    #define left asfdasdasdfasdfsdfasfsdfasfdas1
    #define tan asfdasdasdfasdfasfdfasfsdfasfdas
    typedef long long ll;
    typedef unsigned int un;
    const int desll[4][2]={{0,1},{0,-1},{1,0},{-1,0}};
    const ll mod=1e9+7;
    const int maxn=4e5+7;
    const int maxm=1e6+7;
    const double eps=1e-4;
    int m,n;
    int ar[maxn];
    set<int> se;
    char ch[100];
    int maxx=308983067;
    
    int main()
    {
        scanf("%d",&n);
        int ans=1;
        int l=0,r=maxx;
        bool ma=true;
        int ins=0;
        for(int i=0;i<n;i++){
            int x;
            scanf("%s",ch);
            scanf("%d",&x);
            if(ch[1]=='D'){
                if(se.count(x)==0 && l<x && x<r){
                    se.insert(x);
                    ins++;
                }
                else if(se.count(x)==1){
                    ma=0;
                }
                else{
                    se.insert(x);
                }
            }
            else{
                if(se.count(x)==1 && x<=r && x>=l){
                    if(x!=l&&x!=r)ans = ans*2%mod;
                    set<int>::iterator iter=se.find(x);
                    if(iter==se.begin())l=0;
                    else{
                        iter--;
                        l=*iter;
                        iter++;
                    }
                    se.erase(iter++);
                    if(iter==se.end())r=maxx;
                    else{
                        r=*iter;
                    }
                }
                else{
                    ma=0;
                }
                ins=0;
            }
        }
        if(ins){
            ans = 1LL*ans*(ins+1)%mod;
        }
        if(ma)printf("%d
    ",ans);
        else printf("0
    ");
    
        return 0;
    }
  • 相关阅读:
    js正则表达语法
    Codeforces 976E/925C (01Trie树)
    ZOJ 3879(大模拟)
    CF967C(二分+细节)
    CF967A(细节模拟)
    HDU 2222(AC自动机模板)
    HDU 5510(KMP+思维)
    HDU 6273(树状数组+思维)
    HDU 6266(思维+规律)
    HDU 6264(思维)
  • 原文地址:https://www.cnblogs.com/wa007/p/9551777.html
Copyright © 2011-2022 走看看