QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#482843#9120. Huge Segment Treeucup-team2307TL 58ms15204kbC++202.9kb2024-07-17 22:35:322024-07-17 22:35:33

Judging History

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

  • [2024-07-17 22:35:33]
  • 评测
  • 测评结果:TL
  • 用时:58ms
  • 内存:15204kb
  • [2024-07-17 22:35:32]
  • 提交

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: 100
Accepted
time: 58ms
memory: 14636kb

input:

2

output:

7 3 

result:

ok 2 tokens

Test #2:

score: 0
Accepted
time: 58ms
memory: 14740kb

input:

3

output:

15 14 6 1 

result:

ok 4 tokens

Test #3:

score: 0
Accepted
time: 58ms
memory: 14636kb

input:

4

output:

31 43 36 19 6 1 

result:

ok 6 tokens

Test #4:

score: 0
Accepted
time: 54ms
memory: 14480kb

input:

5

output:

63 110 132 114 70 30 8 1 

result:

ok 8 tokens

Test #5:

score: 0
Accepted
time: 57ms
memory: 14168kb

input:

6

output:

127 255 384 448 400 272 136 47 10 1 

result:

ok 10 tokens

Test #6:

score: 0
Accepted
time: 58ms
memory: 15164kb

input:

7

output:

255 558 978 1401 1610 1478 1066 589 240 68 12 1 

result:

ok 12 tokens

Test #7:

score: 0
Accepted
time: 54ms
memory: 14340kb

input:

8

output:

511 1179 2292 3803 5250 5987 5576 4183 2482 1137 388 93 14 1 

result:

ok 14 tokens

Test #8:

score: 0
Accepted
time: 58ms
memory: 15204kb

input:

9

output:

1023 2438 5088 9398 14896 20038 22632 21250 16406 10282 5144 2006 588 122 16 1 

result:

ok 16 tokens

Test #9:

score: 0
Accepted
time: 54ms
memory: 14928kb

input:

10

output:

2047 4975 10896 21772 38360 58724 77184 86312 81448 64324 42112 22576 9744 3304 848 155 18 1 

result:

ok 18 tokens

Test #10:

score: 0
Accepted
time: 54ms
memory: 13832kb

input:

11

output:

4095 10070 22782 48209 92140 156292 232068 298744 330926 313422 252186 171122 97008 45368 17200 5155 1176 192 20 1 

result:

ok 20 tokens

Test #11:

score: -100
Time Limit Exceeded

input:

500000

output:


result: