QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#297556#4903. 细菌luyiming12315 106ms21460kbC++144.8kb2024-01-04 18:47:582024-01-04 18:48:00

Judging History

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

  • [2024-01-04 18:48:00]
  • 评测
  • 测评结果:15
  • 用时:106ms
  • 内存:21460kb
  • [2024-01-04 18:47:58]
  • 提交

answer

# include <bits/stdc++.h>
using namespace std;
using i64 = long long;
using ui64 = unsigned long long; 
const int N = 2.4e5 + 5; 
const i64 mod = 998244353, ivg = (mod + 1) / 3; 
void Add(i64 &x, i64 y) {x = (x + y) % mod; if(x < 0) x += mod; return; } 
int d, lim[3], pos[3], r[N], L; 
i64 Poly[3][N], sumC[N], fac[N], ifac[N]; 

i64 qpow(i64 x, i64 p = mod - 2ll)
{
    i64 ans = 1ll;
    while(p)
    {
        if(p & 1) ans = ans * x % mod; 
        x = x * x % mod, p >>= 1;
    }
    return ans; 
}

void NTT(i64 *a, bool type) {
	static ui64 f[N], w[N];
	for(int i = 0; i < L; i++) f[i] = a[r[i] = (r[i >> 1] >> 1) | (i & 1 ? L >> 1 : 0)];
	for(int d = 1; d < L; d <<= 1) {
		int wd = qpow(type ? 3 : ivg, (mod - 1) / (d + d));
		for(int j = w[0] = 1; j < d; j++) w[j] = 1ll * w[j - 1] * wd % mod;
		for(int i = 0; i < L; i += d << 1) {
			for(int j = 0; j < d; j++) {
				int y = w[j] * f[i | j | d] % mod;
				f[i | j | d] = f[i | j] + mod - y, f[i | j] += y;
			}
		}
		if(d == (1 << 16)) for(int p = 0; p < L; p++) f[p] %= mod;
	}
	i64 inv = qpow(L, mod - 2);
	for(int i = 0; i < L; i++) a[i] = f[i] % mod * (type ? 1 : inv) % mod;
}

void Init(int n = N - 5)
{
    fac[0] = ifac[0] = 1ll; 
    for(int i = 1; i <= n; i++) fac[i] = fac[i - 1] * 1ll * i % mod; 
    ifac[n] = qpow(fac[n]); 
    for(int i = n - 1; i >= 1; i--) ifac[i] = ifac[i + 1] * 1ll * (i + 1) % mod; 
    return; 
}

i64 C(int n, int m)
{
	if(n < m) return 0; 
	return fac[n] * ifac[m] % mod * ifac[n - m] % mod; 
}

void solve(int o, int d)
{
	// bool deb = (o == 0 && d == 1); 
	bool deb = 1; 
	// printf("solve : %d, %d\n", o, d); 
    int lim = ::lim[o], pos = ::pos[o]; 
    // Line : y = 0, y = lim + 1
    // Line : y = lim + 1 最后被触碰
    i64 Ans = 0; 
    // int lf = 0, rg = lim + 1; 
    int mx = min(d, (lim - pos + d) / 2), mn = (d + 1) / 2; 
	// printf("mx = %d, mn = %d\n", mx, mn); 
    Add(Ans, sumC[mx] - (mn > 0 ? sumC[mn - 1] : 0)); 
    //[lf, pos - 1]
	if(pos > 1)
	{		
		mx = (d - 1) / 2, mn = max(0, (2 - pos + d) / 2); 
		// printf("2 : mx = %d, mn = %d\n", mx, mn); 
		Add(Ans, sumC[mx] - (mn > 0 ? sumC[mn - 1] : 0)); 
	}
	// if(deb) printf("Answer = %lld\n", Ans);  
    for(int i = 1; i * (lim + 1) + 1 <= pos + d; i++)
    {
        int lf = i * (lim + 1) + 1, rg = min((i + 1) * (lim + 1) - 1, pos + d); 
        int mx = (rg - pos + d) / 2, mn = (lf - pos + d + 1) / 2; 
        Add(Ans, ((i & 1) ? -1 : 1) * (sumC[mx] - (mn > 0 ? sumC[mn - 1] : 0))); 
    }

    // Line : y = 0 最后被触碰 pos reverse
    pos = lim - pos + 1; 
    for(int i = 1; i * (lim + 1) + 1 <= pos + d; i++)
    {
        int lf = i * (lim + 1) + 1, rg = min((i + 1) * (lim + 1) - 1, pos + d); 
        int mx = (rg - pos + d) / 2, mn = (lf - pos + d + 1) / 2; 
		// printf("fuck : mx = %d, mn = %d\n", mx, mn); 
        Add(Ans, ((i & 1) ? -1 : 1) * (sumC[mx] - (mn > 0 ? sumC[mn - 1] : 0))); 
    }
    Poly[o][d] = Ans; 
	// printf("fkkkk!\n"); 
    return; 
}

void solve2(int o)
{
    int lim = ::lim[o], pos = ::pos[o]; 
    static i64 dp[2][N];
    int lf = 1 - pos + d, rg = lim - pos + d; 
    for(int i = 0; i <= (d << 1); i++) dp[0][i] = dp[1][i] = 0; 
    dp[0][d] = 1; 
    Poly[o][0] = 1; 
    for(int i = 1; i <= d; i++)
    {
        int op = (i & 1); 
        for(int j = 0; j <= (d << 1); j++) dp[op][j] = 0; 
        for(int j = lf; j <= rg; j++)
        {
            if(j < rg) Add(dp[op][j + 1], dp[op ^ 1][j]); 
            if(j > lf) Add(dp[op][j - 1], dp[op ^ 1][j]); 
        }
        Poly[o][i] = 0; 
        for(int j = lf; j <= rg; j++) Add(Poly[o][i], dp[op][j]); 
    }
    return; 
}

int main(void)
{
    Init(); 
    scanf("%d", &d);
    for(int i = 0; i < 3; i++) scanf("%d", &lim[i]); 
    for(int i = 0; i < 3; i++) scanf("%d", &pos[i]); 

    //init sumC[i] (means C(d, 1) + ... + C(d, i))
	// printf("YES1\n"); 
    for(int o = 0; o < 3; o++) 
    {
        if(1ll * d < 1ll * lim[o] * lim[o]) 
        {
			Poly[o][0] = 1; 
			for(int i = 0; i <= d; i++) sumC[i] = 0; 
			sumC[0] = 1; 
            for(int d0 = 1; d0 <= d; d0++) 
			{
				for(int i = 0; i < d0; i++)
				{
					sumC[i] = sumC[i] * 2ll % mod - C(d0 - 1, i);
				}
				sumC[d0] = sumC[d0 - 1] + 1; 
				solve(o, d0); 
			}
        }
        else solve2(o); 
		// for(int i = 0; i <= d; i++) printf("Poly[%d][%d] = %lld\n", o, i, Poly[o][i]); 
		// printf("Yes : o = %d\n", o); 
    }
	for(int o = 0; o < 3; o++)
	{
		for(int i = 0; i <= d; i++) Poly[o][i] = Poly[o][i] * ifac[i] % mod; 
	}
	L = 1; 
	while(L <= (d << 1)) L <<= 1; 
	for(int o = 0; o < 3; o++) NTT(Poly[o], 1); 
	for(int i = 0; i < L; i++) Poly[0][i] = Poly[0][i] * Poly[1][i] % mod * Poly[2][i] % mod; 
	NTT(Poly[0], 0); 
	printf("%lld\n", Poly[0][d] * fac[d] % mod); 
    return 0;  
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 5
Accepted

Test #1:

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

input:

50 41 46 42 8 20 21

output:

791406134

result:

ok 1 number(s): "791406134"

Test #2:

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

input:

50 49 44 48 49 15 25

output:

544847893

result:

ok 1 number(s): "544847893"

Subtask #2:

score: 10
Accepted

Dependency #1:

100%
Accepted

Test #3:

score: 10
Accepted
time: 101ms
memory: 20660kb

input:

5000 4994 4990 4990 976 2257 2505

output:

836390717

result:

ok 1 number(s): "836390717"

Test #4:

score: 0
Accepted
time: 106ms
memory: 21460kb

input:

5000 4994 4997 4994 4399 1826 1332

output:

65414465

result:

ok 1 number(s): "65414465"

Subtask #3:

score: 0
Time Limit Exceeded

Test #5:

score: 0
Time Limit Exceeded

input:

120000 300 1 1 141 1 1

output:


result:


Subtask #4:

score: 0
Time Limit Exceeded

Test #8:

score: 0
Time Limit Exceeded

input:

119000 119991 119991 1 23819 52139 1

output:


result:


Subtask #5:

score: 0
Skipped

Dependency #4:

0%

Subtask #6:

score: 0
Skipped

Dependency #3:

0%

Subtask #7:

score: 0
Skipped

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Dependency #3:

0%