QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#34487#4245. Equal MEXyzhangWA 2ms3608kbC++171.9kb2022-06-10 08:15:072022-06-10 08:15:07

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-06-10 08:15:07]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:3608kb
  • [2022-06-10 08:15:07]
  • 提交

answer

//μ's forever
#include <bits/stdc++.h>
#define N 300005
#define mod 998244353
//#define getchar nc
using namespace std;
inline char nc(){
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
inline int read()
{
    register int x=0,f=1;register char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9')x=(x<<3)+(x<<1)+ch-'0',ch=getchar();
    return x*f;
}
inline void write(register int x)
{
    if(!x)putchar('0');if(x<0)x=-x,putchar('-');
    static int sta[20];register int tot=0;
    while(x)sta[tot++]=x%10,x/=10;
    while(tot)putchar(sta[--tot]+48);
}
inline void add(int &x,int y){
    x+=y; if(x>=mod) x-=mod;
}
int T,n;
int a[N],vis[N];
int f[N];
int cnt;
int main()
{
    T=read();
    while(T--){
        n=read();
        for(int i=0;i<=n;++i) vis[i]=f[i]=0;
        for(int i=1;i<=n;++i){
            a[i]=read();
            vis[a[i]]=1;
        }
        int val=0;
        while(vis[val]) ++val;
        if(val==0){
            int ans=1;
            for(int i=1;i<=n-1;++i) add(ans,ans);
            printf("%d\n",ans);
            return 0;
        }
        f[0]=1;
        for(int i=0;i<=n;++i) vis[i]=0;
        int l=0,r=0;
        cnt=0;
        while(cnt<val){
            ++r;
            if(a[r]<val){
                if(++vis[a[r]]==1) ++cnt;
            }
        }
        for(int i=0;i<n;++i){
            add(f[i],f[i-1]);
            if(cnt==val) add(f[r],f[i]);
            ++l;
            if(a[l]<val){
                if(--vis[a[l]]==0) --cnt;
            }
            while(r<n&&cnt<val){
                ++r;
                if(a[r]<val){
                    if(++vis[a[r]]==1) ++cnt;
                }
            }
        }
        printf("%d\n",f[n]);
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 2ms
memory: 3608kb

input:

4
6
0 0 0 1 1 1
5
0 1 0 1 0
4
0 0 0 0
3
3 3 3

output:

0
3
8
4

result:

wrong answer 1st numbers differ - expected: '1', found: '0'