QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#822509#9886. Long Sequence Inversion 2Woxuany1#WA 109ms12108kbC++232.1kb2024-12-20 13:41:342024-12-20 13:41:34

Judging History

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

  • [2024-12-20 13:41:34]
  • 评测
  • 测评结果:WA
  • 用时:109ms
  • 内存:12108kb
  • [2024-12-20 13:41:34]
  • 提交

answer

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

ll mod = 998244353;

int L, B, P[500010], f[500010];
vector<int> V[500010];

ll qpow(ll x, ll k)
{
    ll re = 1;
    while (k)
    {
        if (k & 1) re = re * x % mod;
        k >>= 1;
        x = x * x % mod;
    }
    return re;
}

int minn[500010], tree[500010];

void add(int a[], int x, int k, int up)
{
    while (x <= up)
    {
        a[x] += k;
        x = x + (x & -x);
    }
}

int sum(int a[], int x)
{
    int re = 0;
    while (x)
    {
        re += a[x];
        x -= (x & -x);
    }
    return re;
}


bool cmp(int x, int y)
{
    return P[x] > P[y];
}

int main()
{

    // ios::sync_with_stdio(false);
    // cin.tie(0);

    cin >> L >> B;
    for (int i = 0; i < L; i++)
    {
        cin >> P[i];
    }
    for (int i = 0; i < L; i++)
    {
        for (int j = 0; j < B; j++)
        {
            int c;
            cin >> c;
            V[i].push_back(c);
        }
    }

    for (int i = 0; i < L; i++)
    {
        add(tree, P[i] + 1, 1, L);
        minn[i] = sum(tree, P[i] + 1);
    }

    for (int i = 0; i < L; i++)
    {

        f[i] = i;
    }
    sort(f, f + L, cmp);

    ll ans = 0;

    for (int k = L; k >= 1; k--)
    {
        int j = f[L - k];
        ll inv = 0;
        for (int i = 0; i <= B; i++)
        {
            tree[i] = 0;
        }
        for (int i = 0; i < B; i++)
        {
            //cout<<V[j][i]<<" ";
            add(tree, V[j][i] + 1, 1, B);
            inv += sum(tree, B) - sum(tree, V[j][i] + 1);
        }
        inv %= mod;
        ans += (qpow(B, k - minn[j]) * inv % mod
            + (B - 1) * B / 2 % mod
                * ( (qpow(B, k - minn[j]) - 1)
                * qpow(B, k - minn[j]) / 2 % mod ) ) % mod
            * qpow(B, 2 * (minn[j] - 1)) % mod * qpow(B, L - k) % mod;
        //cout<<(B-1)*B/2%mod * ( (qpow(B,k-minn[j])-1) * qpow(B, k-minn[j])/2%mod) %mod * qpow(B,L-k)%mod<<" ";
        //cout << ans << " ";
        ans %= mod;
    }

    cout << ans;

    return 0;
}

/*
3 3
1 2 0
0 1 2
1 2 0
2 0 1


 */

詳細信息

Test #1:

score: 100
Accepted
time: 2ms
memory: 9760kb

input:

3 2
2 0 1
1 0
1 0
0 1

output:

14

result:

ok "14"

Test #2:

score: 0
Accepted
time: 0ms
memory: 9836kb

input:

2 4
1 0
2 0 3 1
1 2 3 0

output:

60

result:

ok "60"

Test #3:

score: 0
Accepted
time: 1ms
memory: 9756kb

input:

9 10
2 5 7 3 8 1 4 6 0
9 2 4 0 1 6 7 3 5 8
4 1 6 7 8 0 5 9 2 3
1 9 2 4 6 8 5 7 0 3
9 0 8 2 5 1 6 7 3 4
1 6 0 7 3 9 2 4 5 8
4 5 2 9 1 6 7 3 0 8
7 0 5 6 1 9 2 4 3 8
3 2 1 6 7 0 8 9 4 5
9 2 4 3 5 8 0 6 7 1

output:

138876070

result:

ok "138876070"

Test #4:

score: 0
Accepted
time: 109ms
memory: 11580kb

input:

1 499999
0
29619 375702 37496 460566 304389 460489 39603 7903 258016 288263 472075 22596 331493 275661 56064 364938 166384 286514 449089 71295 83634 202532 408346 34349 425929 67826 14897 21894 481996 394928 368071 394991 213881 134433 345718 371785 68019 323247 290861 175555 464454 99312 318279 474...

output:

633597495

result:

ok "633597495"

Test #5:

score: 0
Accepted
time: 105ms
memory: 12108kb

input:

2 249999
0 1
58555 86505 217289 160736 134400 101021 40586 62145 139626 85795 167411 201337 98 206983 47713 102694 69929 120989 89299 38007 101502 27064 176770 192694 169507 5163 4199 146210 77723 135393 61474 73326 132827 234968 141265 84204 225082 101831 136349 51115 81706 174808 187315 54745 2076...

output:

434358382

result:

ok "434358382"

Test #6:

score: -100
Wrong Answer
time: 101ms
memory: 11944kb

input:

3 166665
1 0 2
149754 119575 144273 87381 53800 132528 160539 144804 131044 71756 48801 102732 165255 134183 209 129510 122930 87083 34658 111061 142811 141126 65071 45113 142272 2250 137690 86010 2090 101555 148432 56852 17952 53004 11972 36883 144729 44003 59504 11894 15877 47449 95378 59419 12379...

output:

553705889

result:

wrong answer 1st words differ - expected: '906627900', found: '553705889'