QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#398895#5047. Permutation2745518585WA 82ms4108kbC++202.1kb2024-04-25 19:35:082024-04-25 19:35:08

Judging History

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

  • [2024-04-25 19:35:08]
  • 评测
  • 测评结果:WA
  • 用时:82ms
  • 内存:4108kb
  • [2024-04-25 19:35:08]
  • 提交

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=0,f[t].rs=f[x].rs;
                    if(t+k<f[t].r) f[t].ls+=k;
                    Set.insert(t);
                    if(f[t].ls+f[t].rs>=f[t].r-f[t].l-1)
                    {
                        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=0;
                    if(t-k>f[x].l) f[x].rs+=k;
                }
                else
                {
                    Set.erase(x);
                    continue;
                }
            }
            if(f[x].ls+f[x].rs>=f[x].r-f[x].l-1)
            {
                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: 1ms
memory: 3808kb

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: 0
Accepted
time: 82ms
memory: 4108kb

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
12
1
6
6
24
18
2
18
4
6
6
18
6
4
1
6
18
1
6
24
18
6
1
12
18
6
4
2
24
12
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
12
1
4
4
6
24
18
6
2
6
1
12
6
24
1
4
6
1
1
6
1
1
24
12
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:

ok 100000 numbers

Test #3:

score: -100
Wrong Answer
time: 14ms
memory: 3820kb

input:

10000
10 2
7 4 2 9 1 3 10 5 8 6
10 7
10 6 1 5 2 4 7 9 8 3
10 4
10 7 6 2 8 1 5 4 3 9
10 4
4 9 6 2 10 7 8 5 1 3
10 5
9 8 7 4 5 3 2 10 6 1
10 3
5 7 8 1 9 4 6 10 3 2
10 4
6 2 10 8 4 7 9 5 3 1
10 5
10 1 3 7 5 9 4 2 8 6
10 7
10 3 4 5 6 1 9 2 8 7
10 4
1 8 9 7 5 6 3 10 4 2
10 3
6 7 3 1 9 4 10 8 5 2
10 3
5 1...

output:

576
5040
2304
24
201600
720
5040
120
1
40320
720
120
1
720
120
120
2160
161280
480
1
480
1
108
24
1
432
25200
1
30240
35280
35280
720
2160
768
1296
120
35280
20160
432
432
8
201600
192
432
161280
201600
2304
720
5760
576
1
120
201600
576
360
241920
40320
24
1
1
1
35280
1
1
1
3600
720
108
720
1
1296
...

result:

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