QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#482844#9120. Huge Segment Treeucup-team2307WA 60ms10952kbC++202.9kb2024-07-17 22:35:592024-07-17 22:36:00

Judging History

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

  • [2024-07-17 22:36:00]
  • 评测
  • 测评结果:WA
  • 用时:60ms
  • 内存:10952kb
  • [2024-07-17 22:35:59]
  • 提交

answer

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

using ll = long long;
//#define int ll
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
using pii = pair<int, int>;
using vi = vector<int>;
#define fi first
#define se second
#define pb push_back

const ll mod = (119 << 23) + 1, root = 62; // = 998244353
int bpow(int a, int b)
{
    int r = 1;
    while (b>0)
    {
        if (b&1)
            r = r*a%mod;
        a = a*a%mod;
        b /= 2;
    }
    return r;
}
#define modpow bpow
// For p < 2^30 there is also e.g. 5 << 25, 7 << 26, 479 << 21
// and 483 << 21 (same root). The last two are > 10^9.
typedef vector<ll> vl;
void ntt(vl &a) {
	int n = sz(a), L = 31 - __builtin_clz(n);
	static vl rt(2, 1);
	for (static int k = 2, s = 2; k < n; k *= 2, s++) {
		rt.resize(n);
		ll z[] = {1, modpow(root, mod >> s)};
		rep(i,k,2*k) rt[i] = rt[i / 2] * z[i & 1] % mod;
	}
	vi rev(n);
	rep(i,0,n) rev[i] = (rev[i / 2] | (i & 1) << L) / 2;
	rep(i,0,n) if (i < rev[i]) swap(a[i], a[rev[i]]);
	for (int k = 1; k < n; k *= 2)
		for (int i = 0; i < n; i += 2 * k) rep(j,0,k) {
			ll z = rt[j + k] * a[i + j + k] % mod, &ai = a[i + j];
			a[i + j + k] = ai - z + (z > ai ? mod : 0);
			ai += (ai + z >= mod ? z - mod : z);
		}
}
vl conv(const vl &a, const vl &b) {
	if (a.empty() || b.empty()) return {};
	int s = sz(a) + sz(b) - 1, B = 32 - __builtin_clz(s), n = 1 << B;
	int inv = modpow(n, mod - 2);
	vl L(a), R(b), out(n);
	L.resize(n), R.resize(n);
	ntt(L), ntt(R);
	rep(i,0,n) out[-i & (n - 1)] = (ll)L[i] * R[i] % mod * inv % mod;
	ntt(out);
	return {out.begin(), out.begin() + s};
}

//const int mod = 998244353;
const int N = 500500;
int n;
vl a[N], b[N];

vl add(vl a, vl b)
{
    vl c(max(a.size(), b.size()));
    for (int i=0; i<int(a.size()); i++)
        c[i] += a[i];
    for (int i=0; i<int(b.size()); i++)
        c[i] += b[i];
    return c;
}
pair<vl, vl> solve(int l, int r)
{
    if (l == r)
        return {a[l], b[l]};
    else
    {
        int m = (l+r)/2;
        auto A = solve(l, m);
        auto B = solve(m+1, r);
        //(A1*x+A2)*B1+B2
        return {conv(A.fi, B.fi), add(conv(A.se, B.fi), B.se)};
    }
}
int fact[2*N];
int rfact[2*N];
int cnk(int n, int k)
{
    return fact[n]*rfact[n-k]%mod*rfact[k]%mod;
}

signed main()
{
    cin.tie(0)->sync_with_stdio(0);
    cin.exceptions(cin.failbit);

    fact[0] = rfact[0] = 1;
    for (int i=1; i<N; i++)
        fact[i] = fact[i-1]*i%mod, rfact[i] = bpow(fact[i], mod-2);

    cin>>n;
    for (int i=1; i<=n; i++)
    {
        a[i] = {1, 2, 1};
        b[i] = {(bpow(2, i)+mod-2)%mod, (bpow(2, i-1)+mod-1)%mod };
    }
    auto ans = solve(1, n).se;
    ans.resize(2*n-2);
    for (int i=0; i<n; i++)
        ans[i] = (ans[i] + 2*cnk(n, i+1))%mod;
    ans[0]++;
    for (int i : ans)
        cout<<i<<" ";
    cout<<"\n";
}

详细

Test #1:

score: 0
Wrong Answer
time: 60ms
memory: 10952kb

input:

2

output:

7 1 

result:

wrong answer 2nd words differ - expected: '3', found: '1'