QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#768891#6753. MediansDGH_DidiTL 1744ms140148kbC++203.3kb2024-11-21 15:06:312024-11-21 15:06:36

Judging History

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

  • [2024-11-21 15:06:36]
  • 评测
  • 测评结果:TL
  • 用时:1744ms
  • 内存:140148kb
  • [2024-11-21 15:06:31]
  • 提交

answer

#include <bits/stdc++.h>
#define endl '\n'

using namespace std;
using i64 = long long;

template<class T>
constexpr T power(T a, i64 b) {
    T res = 1;
    while (b) {
        if (b & 1) {
            res = res * a;
        }
        b >>= 1;
        a = a * a;
    }
    return res;
}

template<i64 P>
struct ModInt {
    i64 x;
    constexpr ModInt() : x{} {}
    constexpr ModInt(i64 x) : x{norm(x % P)} {}
    constexpr i64 norm(i64 x) const {
        if (x >= P) {
            x -= P;
        } else if (x < 0) {
            x += P;
        }
        return x;
    }
    constexpr i64 val() const {
        return x;
    }
    constexpr ModInt operator-() const {
        ModInt res;
        res.x = norm(P - x);
        return res;
    }
    constexpr ModInt inv() const {
        return power(*this, P - 2);
    }
    constexpr ModInt operator+=(ModInt rhs) & {
        x = norm(x + rhs.x);
        return *this;
    }
    constexpr ModInt operator-=(ModInt rhs) & {
        x = norm(x - rhs.x);
        return *this;
    }
    constexpr ModInt operator*=(ModInt rhs) & {
        x = norm(x * rhs.x % P);
        return *this;
    }
    constexpr ModInt operator/=(ModInt rhs) & {
        return *this *= rhs.inv();
    }
    friend constexpr ModInt operator+(ModInt lhs, ModInt rhs) {
        ModInt res = lhs;
        res += rhs;
        return res;
    }
    friend constexpr ModInt operator-(ModInt lhs, ModInt rhs) {
        ModInt res = lhs;
        res -= rhs;
        return res;
    }
    friend constexpr ModInt operator*(ModInt lhs, ModInt rhs) {
        ModInt res = lhs;
        res *= rhs;
        return res;
    }
    friend constexpr ModInt operator/(ModInt lhs, ModInt rhs) {
        ModInt res = lhs;
        res /= rhs;
        return res;
    }
    friend constexpr bool operator==(ModInt lhs, ModInt rhs) {
        return lhs.val() == rhs.val();
    }
    friend constexpr bool operator!=(ModInt lhs, ModInt rhs) {
        return lhs.val() != rhs.val();
    }
    friend constexpr istream &operator>>(istream &is, ModInt &a) {
        i64 v;
        is >> v;
        a = ModInt(v);
        return is;
    }
    friend constexpr ostream &operator<<(ostream &os, const ModInt &a) {
        return os << a.val();
    }
};

using mint = ModInt<998244353>;

#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;

template<class T>
using Set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

template<class T>
using Multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;

const int N = 1e7 + 5;
int n;
int a[N], p[N];
mint pw[N];

int main() {
    ios::sync_with_stdio(false), cin.tie(0);
    cin >> n >> a[0];
    for (int i = 1; i <= n; i++) {
        a[i] = (1LL * a[i - 1] * 998244353 + 1000000007) % 1000000009;
        p[i] = i;
    }
    for (int i = 1; i <= n; i++) {
        swap(p[i], p[a[i] % i + 1]);
    }

    pw[0] = 1;
    for (int i = 1; i <= n; i++) {
        pw[i] = pw[i - 1] * 19;
    }

    mint ans = 0;
    Set<int> st;
    for (int i = 1; i <= n; i++) {
        st.insert(p[i]);
        ans += pw[i] * (*st.find_by_order((i + 1) / 2 - 1));
    }
    cout << ans << endl;
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

5 0

output:

7703113

result:

ok 1 number(s): "7703113"

Test #2:

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

input:

5 1

output:

7840977

result:

ok 1 number(s): "7840977"

Test #3:

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

input:

2 1361955

output:

399

result:

ok 1 number(s): "399"

Test #4:

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

input:

4 207579012

output:

274740

result:

ok 1 number(s): "274740"

Test #5:

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

input:

8 628145516

output:

783389330

result:

ok 1 number(s): "783389330"

Test #6:

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

input:

16 376140462

output:

772072366

result:

ok 1 number(s): "772072366"

Test #7:

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

input:

32 883515280

output:

822906393

result:

ok 1 number(s): "822906393"

Test #8:

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

input:

64 186969585

output:

536948870

result:

ok 1 number(s): "536948870"

Test #9:

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

input:

128 762888635

output:

914896632

result:

ok 1 number(s): "914896632"

Test #10:

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

input:

256 326402539

output:

816864808

result:

ok 1 number(s): "816864808"

Test #11:

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

input:

512 98152102

output:

792934555

result:

ok 1 number(s): "792934555"

Test #12:

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

input:

1024 158176572

output:

187304261

result:

ok 1 number(s): "187304261"

Test #13:

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

input:

2048 61402883

output:

881629018

result:

ok 1 number(s): "881629018"

Test #14:

score: 0
Accepted
time: 2ms
memory: 7952kb

input:

4096 127860889

output:

926052991

result:

ok 1 number(s): "926052991"

Test #15:

score: 0
Accepted
time: 3ms
memory: 8180kb

input:

8192 9580638

output:

18767865

result:

ok 1 number(s): "18767865"

Test #16:

score: 0
Accepted
time: 5ms
memory: 8620kb

input:

16384 570870044

output:

676635475

result:

ok 1 number(s): "676635475"

Test #17:

score: 0
Accepted
time: 10ms
memory: 11300kb

input:

32768 646139319

output:

121314798

result:

ok 1 number(s): "121314798"

Test #18:

score: 0
Accepted
time: 22ms
memory: 11248kb

input:

65536 178509022

output:

518784793

result:

ok 1 number(s): "518784793"

Test #19:

score: 0
Accepted
time: 50ms
memory: 16836kb

input:

131072 484027666

output:

783563468

result:

ok 1 number(s): "783563468"

Test #20:

score: 0
Accepted
time: 110ms
memory: 26764kb

input:

262144 61263304

output:

560815556

result:

ok 1 number(s): "560815556"

Test #21:

score: 0
Accepted
time: 271ms
memory: 41412kb

input:

524288 841082555

output:

478037004

result:

ok 1 number(s): "478037004"

Test #22:

score: 0
Accepted
time: 709ms
memory: 73372kb

input:

1048576 558212774

output:

145045199

result:

ok 1 number(s): "145045199"

Test #23:

score: 0
Accepted
time: 1744ms
memory: 140148kb

input:

2097152 940563715

output:

267114566

result:

ok 1 number(s): "267114566"

Test #24:

score: -100
Time Limit Exceeded

input:

4194304 26389620

output:


result: