zoukankan      html  css  js  c++  java
  • NOIP 模拟 $94; m 叁仟柒佰万$

    题解 (by;zjvarphi)

    性质:最终有贡献的方案的 (mex) 一定是全局 (mex)

    发现当右端点固定后,左端点 (mex) 值是单调的,所以双指针扫一下即可。

    Code
    #include<bits/stdc++.h>
    #define ri signed
    #define pd(i) ++i
    #define bq(i) --i
    #define func(x) std::function<x>
    namespace IO{
        char buf[1<<21],*p1,*p2;
        #define gc() p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?(-1):*p1++
        #define dg1(x) std::cerr << #x"=" << x << ' '
        #define dg2(x) std::cerr << #x"=" << x << std::endl
        #define Dg(x) assert(x)
        struct nanfeng_stream{
            template<typename T>inline nanfeng_stream &operator>>(T &x) {
                bool f=false;x=0;char ch=gc();
                while(!isdigit(ch)) f|=ch=='-',ch=gc();
                while(isdigit(ch)) x=(x<<1)+(x<<3)+(ch^48),ch=gc();
                return x=f?-x:x,*this;
            }
        }cin;
    }
    using IO::cin;
    namespace nanfeng{
        #define FI FILE *IN
        #define FO FILE *OUT
        template<typename T>inline T cmax(T x,T y) {return x>y?x:y;}
        template<typename T>inline T cmin(T x,T y) {return x>y?y:x;}
        static const int N=3e5+7e4+7,MOD=1e9+7;
        int a[N*100],sum[N],dp[N*100],T,n;
        inline int main() {
            FI=freopen("clods.in","r",stdin);
            FO=freopen("clods.out","w",stdout);
            cin >> T;
            for (ri z(1);z<=T;pd(z)) {
                cin >> n;
                if (n==37000000) {
                    int X,Y;
                    cin >> X >> Y;
                    const int x=X,y=Y;
                    for (ri i(2);i<=n;pd(i)) a[i]=(1ll*a[i-1]*x+y+i)&262143; 
                } else for (ri i(1);i<=n;pd(i)) cin >> a[i];
                int amx=0,bg,pnt=0,l=1,r=1,su,mx=0;
                for (ri i(1);i<=n;pd(i)) {
                    mx=cmax(mx,a[i]);
                    ++sum[a[i]];
                    while(sum[amx]) ++amx;
                }
                memset(sum,0,sizeof(int)*(mx+1));
                for (ri i(1);i<=n;pd(i)) {
                    ++sum[a[i]];
                    while(sum[pnt]) ++pnt;
                    if (pnt==amx) {bg=i;break;}
                }
                su=dp[0]=dp[bg]=1;
                for (ri i(bg+1);i<=n;pd(i)) {
                    ++sum[a[i]];
                    while(r<i&&(sum[a[r]]>1||a[r]>amx)) {
                        if (r>=bg) su+=dp[r];
                        --sum[a[r++]];
                        if (su>=MOD) su-=MOD;
                    }
                    dp[i]=su;
                }
                printf("%d
    ",dp[n]);
                if (z==T) break;
                memset(sum,0,sizeof(int)*(mx+1));
                memset(dp,0,sizeof(int)*(n+1));
            }
            return 0;
        }
    }
    int main() {return nanfeng::main();}
    
  • 相关阅读:
    EntityFramework优缺点
    领导者与管理者的区别
    七个对我最好的职业建议(精简版)
    The best career advice I’ve received
    Difference between Stored Procedure and Function in SQL Server
    2015年上半年一次通过 信息系统项目管理师
    Difference between WCF and Web API and WCF REST and Web Service
    What’s the difference between data mining and data warehousing?
    What is the difference between a Clustered and Non Clustered Index?
    用new创建函数的过程发生了什么
  • 原文地址:https://www.cnblogs.com/nanfeng-blog/p/15538261.html
Copyright © 2011-2022 走看看