编号 题目 状态 分数 总时间 内存 代码 / 答案文件 提交者 提交时间
#7170 #1005. 计算机网络 Accepted 100 2245 ms 14028 K C++ 11 (Clang) / 5.6 K admin 2023-11-21 18:54:46
显示原始代码
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <iostream>
#include <cstring>
#include <bitset>
#include <ctime>
#include <functional>
#include <numeric>
#include <random>
#include <chrono>
#include <array>
#include <utility>

typedef int64_t LL;
typedef uint64_t uLL;
typedef __int128_t sLL;
#define fir first


#define sec second


#define eb emplace_back


#define em emplace


#define pb push_back


#define ppb pop_back


#define pii std::pair<int, int>


#define mkp(a, b) std::make_pair(a, b)


#define bitcount(x) __builtin_popcount(x)


#define bitcountll(x) __builtin_popcountll(x)


#define bitparity(x) __builtin_parity(x)


#define bitparityll(x) __builtin_parityll(x)


int read() {
    int s = 0, w = 1;
    char ch = getchar();
    while (ch < '0' || ch > '9') {
        if (ch == '-')
            w = -1;
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9') s = s * 10 + ch - '0', ch = getchar();
    return s * w;
}

LL readl() {
    LL s = 0, w = 1;
    char ch = getchar();
    while (ch < '0' || ch > '9') {
        if (ch == '-')
            w = -1;
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9') s = s * 10 + ch - '0', ch = getchar();
    return s * w;
}

template <typename T>
void debugv(const T &vec, const char *s = NULL) {
    if (s == NULL) {
        s = "";
    }
    printf("%s = [", s);
    for (const auto &val : vec) {
        std::cout << val << ", ";
    }
    printf("]\n");
}

template <typename key, typename val>
void debugmp(const std::map<key, val> &mp, const char *s = NULL) {
    if (s == NULL) {
        s = "";
    }
    printf("%s = [", s);
    for (const auto &[k, v] : mp) {
        std::cout << "< " << k << ", " << v << " >, ";
    }
    printf("]\n");
}

template <typename T>
void debuga(T *arr, int l, int r, const char *s = NULL) {
    if (s == NULL) {
        s = "";
    }
    printf("%s = [", s);
    for (int i = l; i <= r; i++) {
        std::cout << arr[i] << ", ";
    }
    printf("]\n");
}

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = std::chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

const int maxn = 3e5 + 1;
const int mod = 998244353, g = 3;

#define int int64_t


int ksm(int x, int y) {
    int ret = 1;
    for (; y; y >>= 1, x = x * x % mod)
        if (y & 1)
            ret = ret * x % mod;
    return ret;
}

int rev[maxn];

void NTT(int *a, int n, int typ) {
    for (int i = 0; i < n; i++)
        if (i < rev[i])
            std::swap(a[i], a[rev[i]]);
    for (int i = 1; i < n; i <<= 1) {
        int gn = ksm(g, (mod - 1) / (i << 1));
        for (int j = 0, g0 = 1, x, y; j < n; j += (i << 1), g0 = 1)
            for (int k = 0; k < i; k++, g0 = gn * g0 % mod) {
                x = a[j + k], y = a[i + j + k] * g0 % mod;
                a[j + k] = (x + y) % mod;
                a[i + j + k] = (x - y + mod) % mod;
            }
    }
    if (typ == 1)
        return;
    int inv = ksm(n, mod - 2);
    std::reverse(a + 1, a + n);
    for (int i = 0; i < n; i++) a[i] = a[i] * inv % mod;
    return;
}

void INV(int *b, int *a, int n) {
    if (n == 1)
        return b[0] = ksm(a[0], mod - 2), void();
    INV(b, a, (n + 1) >> 1);
    static int c[maxn];
    int len = 1, p = -1;
    while (len < (n << 1)) len <<= 1, p++;
    for (int i = 1; i <= len - 1; i++) rev[i] = (rev[i >> 1] >> 1) | ((i & 1) << p);
    std::copy(a, a + n, c);
    std::fill(c + n, c + len, 0);
    NTT(c, len, 1), NTT(b, len, 1);
    for (int i = 0; i <= len - 1; i++) b[i] = (2 - b[i] * c[i] % mod + mod) % mod * b[i] % mod;
    NTT(b, len, 0), std::fill(b + n, b + len, 0);
    return;
}

#undef int

int n, k;
LL f[maxn], gg[maxn], frac[maxn], ifrac[maxn];
int a[maxn];

void init() {
    frac[0] = 1;
    for (int i = 1; i < maxn; i++) {
        frac[i] = frac[i - 1] * i % mod;
    }
    ifrac[maxn - 1] = ksm(frac[maxn - 1], mod - 2);
    for (int i = maxn - 2; i >= 0; i--) {
        ifrac[i] = ifrac[i + 1] * (i + 1) % mod;
    }
}

void add(LL &x, int val) {
    x += val;
    if (x >= mod)
        x -= mod;
    if (x < 0)
        x += mod;
}

int32_t main() {
    init();
    n = read();
    k = read();
    for (int i = 1; i <= k; i++) {
        a[i] = read();
        if (a[i] == 2) {
            printf("0\n");
            return 0;
        }
    }
    int mx = *std::max_element(a + 1, a + 1 + k);
    for (int i = 0; i <= n; i++) {
        gg[i] = ksm(2, (LL)i * (i - 1) / 2) * ifrac[i] % mod;
    }
    INV(f, gg, n + 1);
    for (int i = 0; i <= n; i++) {
        f[i] = mod - f[i];
        if (f[i] == mod)
            f[i] = 0;
    }
    add(f[0], 1);
    for (int i = mx; i <= n; i++) {
        f[i] = 0;
    }
    for (int i = 0; i <= n; i++) {
        f[i] = mod - f[i];
        if (f[i] == mod)
            f[i] = 0;
    }
    add(f[0], 1);
    memset(gg, 0, sizeof(gg));
    INV(gg, f, n + 1);
    LL ans = ksm(2, (LL)n * (n - 1) / 2);
    add(ans, -gg[n] * frac[n] % mod);
    printf("%lld\n", ans);
    return 0;
}
子任务 #1
Accepted
得分:100
测试点 #1
Accepted
得分:100
用时:279 ms
内存:13572 KiB

输入文件(1.in

100000 500
31599 6915 91270 1661 29829 55647 23911 18968 18394 72717 62694 72888 68356 45622 52749 
<2852 bytes omitted>

答案文件(1.out

415282073

用户输出

415282073

系统信息

Exited with return code 0
测试点 #2
Accepted
得分:100
用时:261 ms
内存:13632 KiB

输入文件(2.in

100000 5000
29529 44280 90141 35177 83295 17947 47455 86819 74799 2831 38016 37929 32078 44918 9612
<29380 bytes omitted>

答案文件(2.out

388342451

用户输出

388342451

系统信息

Exited with return code 0
测试点 #3
Accepted
得分:100
用时:272 ms
内存:13760 KiB

输入文件(3.in

100000 50000
33701 67714 2164 72781 30104 88239 14380 54251 1838 85079 79349 38676 50112 58278 8238
<294292 bytes omitted>

答案文件(3.out

468044740

用户输出

468044740

系统信息

Exited with return code 0
测试点 #4
Accepted
得分:100
用时:279 ms
内存:14028 KiB

输入文件(4.in

100000 98000
66276 9593 83741 31550 23402 57841 26379 16990 13649 32430 24627 79388 13060 9862 1235
<577030 bytes omitted>

答案文件(4.out

854278657

用户输出

854278657

系统信息

Exited with return code 0
测试点 #5
Accepted
得分:100
用时:14 ms
内存:5392 KiB

输入文件(5.in

100000 98000
61690 76514 14331 51908 13421 21209 75656 28275 72507 28774 5129 51191 10746 30776 689
<577040 bytes omitted>

答案文件(5.out

0

用户输出

0

系统信息

Exited with return code 0
测试点 #6
Accepted
得分:100
用时:284 ms
内存:13996 KiB

输入文件(6.in

100000 98123
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 
<577555 bytes omitted>

答案文件(6.out

657420631

用户输出

657420631

系统信息

Exited with return code 0
测试点 #7
Accepted
得分:100
用时:13 ms
内存:5008 KiB

输入文件(7.in

100000 98123
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 3
<577551 bytes omitted>

答案文件(7.out

0

用户输出

0

系统信息

Exited with return code 0
测试点 #8
Accepted
得分:100
用时:285 ms
内存:13616 KiB

输入文件(8.in

99999 5
67820 82839 68514 54839 53794

答案文件(8.out

164481186

用户输出

164481186

系统信息

Exited with return code 0
测试点 #9
Accepted
得分:100
用时:286 ms
内存:13588 KiB

输入文件(9.in

99999 5
3 4 5 6 7

答案文件(9.out

733878736

用户输出

733878736

系统信息

Exited with return code 0
测试点 #10
Accepted
得分:100
用时:272 ms
内存:13616 KiB

输入文件(10.in

99999 50
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 3
<54 bytes omitted>

答案文件(10.out

832923316

用户输出

832923316

系统信息

Exited with return code 0