QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#398907#5047. Permutation2745518585WA 45ms9972kbC++202.1kb2024-04-25 19:41:452024-04-25 19:41:47

Judging History

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

  • [2024-04-25 19:41:47]
  • 评测
  • 测评结果:WA
  • 用时:45ms
  • 内存:9972kb
  • [2024-04-25 19:41:45]
  • 提交

answer

#include<cstdio>
#include<algorithm>
#include<set>
using namespace std;
typedef long long ll;
const int N=1000001;
const ll P=998244353;
int n,k,a[N],b[N];
ll jc[N];
struct str
{
    int l,r,ls,rs;
}f[N];
int main()
{
    int T;
    scanf("%d",&T);
    while(T--)
    {
        scanf("%d%d",&n,&k);
        for(int i=1;i<=n;++i)
        {
            scanf("%d",&a[i]);
            b[a[i]]=i;
        }
        jc[0]=1;
        for(int i=1;i<=n;++i) jc[i]=jc[i-1]*i%P;
        set<int> Set;
        Set.insert(0);
        for(int i=1;i<=n;++i) f[i].l=f[i].r=f[i].ls=f[i].rs=0;
        f[0].l=0,f[0].r=n+1,f[0].ls=f[0].rs=0;
        ll s=1;
        for(int i=1;i<=n;++i)
        {
            int t=b[i];
            auto p=upper_bound(Set.begin(),Set.end(),t);
            if(p==Set.begin()) continue;
            int x=*prev(p);
            if(f[x].r<=t) continue;
            if(t<=f[x].l+f[x].ls)
            {
                s=s*f[x].ls%P;
                f[x].ls+=k;
            }
            else if(t>=f[x].r-f[x].rs)
            {
                s=s*f[x].rs%P;
                f[x].rs+=k;
            }
            else
            {
                if(t+k<f[x].r)
                {
                    f[t].l=t,f[t].r=f[x].r,f[t].ls=k,f[t].rs=f[x].rs;
                    Set.insert(t);
                    if(f[t].ls+f[t].rs>=f[t].r-f[t].l)
                    {
                        s=s*jc[min(f[t].r,n)-max(f[t].l,1)+1-(f[t].ls+f[t].rs)/k]%P;
                        Set.erase(t);
                    }
                }
                if(t-k>f[x].l)
                {
                    f[x].r=t,f[x].rs=k;
                }
                else
                {
                    Set.erase(x);
                    continue;
                }
            }
            if(f[x].ls+f[x].rs>=f[x].r-f[x].l)
            {
                s=s*jc[min(f[x].r,n)-max(f[x].l,1)+1-(f[x].ls+f[x].rs)/k]%P;
                Set.erase(x);
            }
        }
        printf("%lld\n",s);
    }
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 9972kb

input:

5
5 3
3 4 2 1 5
5 4
4 2 1 3 5
5 2
4 5 3 1 2
5 3
4 3 2 1 5
5 2
2 3 1 5 4

output:

6
1
4
6
4

result:

ok 5 number(s): "6 1 4 6 4"

Test #2:

score: -100
Wrong Answer
time: 45ms
memory: 9840kb

input:

100000
5 4
1 3 2 5 4
5 3
5 1 4 2 3
5 2
1 4 5 3 2
5 4
5 2 4 3 1
5 4
2 5 4 1 3
5 4
1 2 3 5 4
5 4
4 3 2 5 1
5 3
1 5 4 3 2
5 3
3 2 5 4 1
5 4
4 3 1 5 2
5 4
4 3 5 2 1
5 2
3 2 1 4 5
5 3
2 4 5 1 3
5 3
2 1 4 3 5
5 3
2 1 5 4 3
5 2
2 1 3 4 5
5 4
2 3 1 4 5
5 2
1 2 4 5 3
5 3
2 4 1 5 3
5 3
2 4 3 5 1
5 3
4 1 3 5 2...

output:

24
6
6
24
1
24
24
6
18
1
24
4
6
6
6
4
1
16
1
6
6
24
18
2
18
4
6
6
18
6
4
1
6
18
1
6
24
18
6
1
16
18
6
4
2
24
16
4
24
4
4
24
6
1
1
1
1
6
1
4
1
18
1
18
4
4
6
24
6
4
6
1
16
1
4
4
6
24
18
6
2
6
1
16
6
24
1
4
6
1
1
6
1
1
24
16
18
1
4
18
1
4
24
6
4
24
6
24
1
1
6
1
18
24
1
4
1
1
2
6
1
6
4
18
1
24
6
6
4
24
...

result:

wrong answer 18th numbers differ - expected: '12', found: '16'