QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#826785#9886. Long Sequence Inversion 2ucup-team3519#WA 45ms11100kbC++173.0kb2024-12-22 16:08:182024-12-22 16:08:20

Judging History

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

  • [2024-12-22 16:08:20]
  • 评测
  • 测评结果:WA
  • 用时:45ms
  • 内存:11100kb
  • [2024-12-22 16:08:18]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

#define V vector
#define pb push_back
#define fi first
#define se second
#define all0(x) (x).begin(), (x).end()
#define all1(x) (x).begin() + 1, (x).end()

typedef long long LL;
typedef pair<int, int> pi;

const LL mod = 998244353;
LL MOD(LL x) {
    if (x >= mod) return x - mod;
    if (x < 0) return x + mod;
    return x;
}

const int N = 5e5 + 1000;

struct BIT {
    LL fen[N];
    void add(int x, LL d) {
        x++;
        while (x < N) {
            fen[x] += d;
            x += x & -x;
        }
    }
    LL query(int x) {
        x++;
        LL ans = 0;
        while (x) ans += fen[x], x -= x & -x;
        return ans;
    }
    LL query(int l, int r) { return query(r) - query(l - 1); }
} fen;

LL cal_inv(V<int> a) {
    int n = a.size();
    for (int i = 0; i < n + 10; i++) fen.fen[i] = 0;
    LL ans = 0;
    for (int i = 0; i < n; i++) {
        // for (int j = 0; j < n; j++) {
        //     cout << fen.query(j, j) << " ";
        // }
        // cout << "\n";
        // for (int j = 1; j <= n; j++) {
        //     cout << fen.fen[j] << " ";
        // }
        // cout << "\n";
        ans += fen.query(a[i], n - 1);
        fen.add(a[i], 1);
    }
    return ans;
}

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

LL inv2 = qpow(2, mod - 2);

LL sum(LL l, LL r) { return (l + r) * (r - l + 1) % mod * inv2 % mod; }

void solve() {
    int L, B;
    cin >> L >> B;
    V<LL> pbb(L * 2);
    pbb[0] = 1;
    for (int i = 1; i < L * 2; i++) {
        pbb[i] = pbb[i - 1] * B % mod;
    }
    V<int> p(L);
    for (int i = 0; i < L; i++) cin >> p[i];
    V<V<int>> v(L, V<int>(B));
    for (int i = 0; i < L; i++) {
        for (int j = 0; j < B; j++) {
            cin >> v[i][j];
        }
    }
    V<LL> t(L);
    for (int i = 0; i < L; i++) t[i] = cal_inv(v[i]) % mod;
    V<int> g(L);
    for (int i = 1; i <= L + 10; i++) {
        fen.fen[i] = 0;
    }
    for (int i = L - 1; i >= 0; i--) {
        g[i] = fen.query(0, p[i]);
        fen.add(p[i], 1);
    }
    V<LL> f(L);
    for (int i = 0; i < L; i++) {
        f[i] = MOD(pbb[2 * p[i] - g[i]] * t[i] % mod +
                   sum(0, pbb[g[i]] - 1) * sum(0, B - 1) % mod *
                       pbb[2 * p[i] - 2 * g[i]]);
    }
    // cout << "g : " << "\n";
    // for (int i = 0; i < L; i++) {
    //     cout << g[i] << " ";
    // }
    // cout << "\n";
    // cout << "t : " << "\n";
    // for (int i = 0; i < L; i++) {
    //     cout << t[i] << " ";
    // }
    // cout << "\n";
    // cout << "f : " << "\n";
    // for (int i = 0; i < L; i++) {
    //     cout << f[i] << " ";
    // }
    // cout << "\n";
    LL ans = 0;
    for (int i = 0; i < L; i++) {
        ans = MOD(ans + pbb[L - 1 - p[i]] * f[i] % mod);
    }
    cout << ans << "\n";
}
int main() {
    ios::sync_with_stdio(0), cin.tie(0);
    solve();
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 5568kb

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: 5628kb

input:

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

output:

60

result:

ok "60"

Test #3:

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

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: 45ms
memory: 11100kb

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: 42ms
memory: 8568kb

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: 0
Accepted
time: 37ms
memory: 8796kb

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:

906627900

result:

ok "906627900"

Test #7:

score: 0
Accepted
time: 29ms
memory: 8592kb

input:

4 124999
2 1 0 3
6758 121850 37185 80215 73912 42468 46605 75414 112915 110077 22953 23013 97274 13521 49377 118836 81264 34203 17001 55248 75687 111368 83888 8716 40342 34360 114608 49408 91858 84412 45961 7941 14659 13108 93982 12542 100883 88893 77840 24386 115013 55592 36874 19448 55866 117277 5...

output:

783661427

result:

ok "783661427"

Test #8:

score: -100
Wrong Answer
time: 39ms
memory: 8256kb

input:

5 99999
1 2 0 4 3
59880 90678 66325 71329 58429 10918 50915 81996 24439 90993 49857 91190 60989 21075 94746 42666 9319 72804 79261 60359 83848 27702 86471 32161 13537 75754 38237 8840 55918 4178 8934 35695 23232 76054 17267 46410 12231 41364 80427 84377 99775 98696 10888 60764 72426 67093 83038 9642...

output:

414028549

result:

wrong answer 1st words differ - expected: '943262391', found: '414028549'