QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#814047#9886. Long Sequence Inversion 2ucup-team093#WA 39ms7080kbC++201.9kb2024-12-14 14:50:332024-12-14 14:50:35

Judging History

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

  • [2024-12-14 14:50:35]
  • 评测
  • 测评结果:WA
  • 用时:39ms
  • 内存:7080kb
  • [2024-12-14 14:50:33]
  • 提交

answer

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

using i64 = long long;
const int P = 998244353;

int ask(vector<int> &tr, int p) {
    int ret = 0;
    while(p < tr.size()) {
        ret += tr[p];
        p += ((p + 1) & (-p - 1));
    }
    return ret;
}

void add(vector<int> &tr, int p) {
    while(p >= 0) {
        tr[p] ++;
        p -= ((p + 1) & (-p - 1));
    }
}

int calc(vector<int> &a) {
    vector<int> tr(a.size());
    int ret = 0;
    for(int x : a) {
        ret += ask(tr, x);
        add(tr, x);
    }
    return ret;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int L, B;
    cin >> L >> B;
    
    vector<int> bpow(L + 1);
    bpow[0] = 1;
    for(int i = 1; i <= L; i ++)
        bpow[i] = bpow[i - 1] * (i64)B % P;
    
    vector<int> p(L);
    for(int i = 0; i < L; i ++) cin >> p[i];

    vector<vector<int> > v(L, vector<int>(B));
    for(int i = 0; i < L; i ++)
        for(int j = 0; j < B; j ++)
            cin >> v[i][j];
    
    int ans = 0;
    vector<int> tr(L);
    for(int i = 0; i < L; i ++) {
        int x = ask(tr, p[i]) + L - i - 1, y = L - 1 - x;
        int z = L - p[i] - 1, q = p[i] + 1;
        //cout << i << ": " << z << " " << q << " | " << (bpow[x] * (i64)bpow[y] % P * (i64)bpow[y]) << " " << calc(v[i]) << " " << (((bpow[q] * ((i64)bpow[q] - bpow[q - 1]) / 2) % P * bpow[z]) % P + P - (bpow[x] * (i64)bpow[y] % P * (i64)bpow[y] % P * (B * (B - 1ll) / 2 % P)) % P) * ((P + 1ll) / 2) % P << "\n";
        ans = (ans + (bpow[x] * (i64)bpow[y] % P * (i64)bpow[y]) % P * calc(v[i])) % P;
        ans = (ans + (((bpow[q] * ((i64)P + bpow[q] - bpow[q - 1]) % P * ((P + 1ll) / 2)) % P * bpow[z]) % P + P - (bpow[x] * (i64)bpow[y] % P * (i64)bpow[y] % P * (B * (B - 1ll) / 2 % P)) % P) * ((P + 1ll) / 2) % P) % P;
        add(tr, p[i]);
    }
    cout << ans << "\n";
}

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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

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

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: -100
Wrong Answer
time: 39ms
memory: 7080kb

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:

-901517706

result:

wrong answer 1st words differ - expected: '633597495', found: '-901517706'