• 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;
    }
  • 相关阅读:
    python ddt 传多个参数值示例
    Appium 输入 & 符号,实际输入&-
    curl 调用jenkins的api
    Android WebView的Js对象注入漏洞解决方案
    Could not find com.android.tools.build:gradle:1.3.0.
    react-native疑难
    win上搭建react-native android环境
    gradle大体内容
    android studio This client is too old to work with the working copy at
    sharedPreference
  • 原文地址:https://www.cnblogs.com/wa007/p/9551777.html
Copyright © 2020-2023  润新知