QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#406788#5099. 朝圣道ningago0 119ms26488kbC++145.5kb2024-05-07 18:27:562024-05-07 18:27:57

Judging History

This is the latest submission verdict.

  • [2024-05-07 18:27:57]
  • Judged
  • Verdict: 0
  • Time: 119ms
  • Memory: 26488kb
  • [2024-05-07 18:27:56]
  • Submitted

answer

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <map>
#include <cmath>
#include <cctype>
#include <set>
#include "pilgrimage.h"

namespace uvu
{
#define LOCAL ____________DONT_DEFINE_ME____________
// #define ll long long
// #define inf 0x3f3f3f3f
#define int long long
#define inf 0x3f3f3f3f3f3f3f3fll
#define infll 0x3f3f3f3f3f3f3f3fll
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define gline debug("now is #%d\n", __LINE__)
#define pii std::pair <int, int>
#define mkp std::make_pair
#define fi first
#define se second
char _ST_;
const int BUFSIZE = (1 << 20);
char ibuf[BUFSIZE], *iS = ibuf, *iT = ibuf;
char obuf[BUFSIZE], *oS = obuf, *oT = obuf + BUFSIZE;
char getc()
{
#ifdef LOCAL
	return getchar();
#else
	if(iS == iT) iT = (iS = ibuf) + fread(ibuf, 1, BUFSIZE, stdin);
	return iS == iT ? EOF : *iS++;
#endif
#define getchar ERR
}

void Flush() { fwrite(obuf, 1, oS - obuf, stdout); oS = obuf; }
struct Flusher { ~Flusher(){ Flush(); } }iamflusher;

void putc(char c)
{
#ifdef LOCAL
	putchar(c);
#else
	*oS++ = c;
	if(oS == oT) Flush();
#endif
#define putchar ERR
}

template <typename T = int> T read()
{
	T x = 0, f = 1; char c = getc();
	for(; !isdigit(c); c = getc()) if(c == '-') f = -1;
	for(;  isdigit(c); c = getc()) x = (x << 3) + (x << 1) + (c ^ 48);
	return x * f;
}

template <typename T> void print(T x, char c)
{
static int sta[BUFSIZE], top;
	top = 0;
	if(x < 0) putc('-'), x = -x;
	if(!x) sta[top = 1] = 0;
	for(; x; x /= 10) sta[++top] = x % 10;
	for(; top; ) putc(sta[top--] ^ 48);
	if(c) putc(c);
}

int readstr(char *s, int base)
{
	int idx = base - 1; char c = getc();
	for(; !(isdigit(c) || isalpha(c) || c == '#' || c == '.'); c = getc());
	for(;   isdigit(c) || isalpha(c) || c == '#' || c == '.' ; c = getc()) s[++idx] = c;
	return idx - base + 1;
}

void printf(const char *s) { for(; *s; s++) putc(*s); }
template <typename T, typename ... Args>
void printf(const char *s, T x, Args ... rest)
{
	for(; *s; s++)
	{
		if(*s != '%') { putc(*s); continue; }
		s++; if(*s == 'd') print(x, 0);
		else if(*s == 'c') putc(x);
		printf(s + 1, rest ...);
		return;
	}
}

template <typename T> void ckmax(T &x, T y) { x = x > y ? x : y; }
template <typename T> void ckmin(T &x, T y) { x = x < y ? x : y; }
// #define mod 998244353
// #define mod 1000000007
// int mod;
// int sm(int x) { return x >= mod ? x - mod : x; }
// void plus_(int &x, int y) { x = sm(x + y); }
// void mul_(int &x, int y) { x = 1ll * x * y % mod; }
int ksm(int a, int b, int mod) { int res = 1; for(; b; b >>= 1, a = 1ll * a * a % mod) if(b & 1) res = 1ll * res * a % mod; return res; }
int id, k_[1000];
std::vector <int> pre[1000];
std::vector <int> invv[1000];
std::vector <int> poww[1000];
int f(int n, int p, int pk, int &tot)
{
	if(!n) return 1;
	int res = pre[id][pk - 1];
	res = ksm(res, n / pk, pk);
	res = 1ll * res * f(n / p, p, pk, tot) % pk;
	tot += n / p;
	res = 1ll * res * pre[id][n % pk] % pk;
	// for(int i = n / pk * pk; i <= n; i++) if(i % p) res = 1ll * res * (i % pk) % pk;//, !res && ::printf("i = %lld, res = %lld\n", i, res);
	// printf("f(%d %d %d) = %d\n", n, p, pk, res);
	return res;
}
// 0 9 999983
// 1
// 2
// 3
// 4
// 5
// 12
// 2999
// 999999
// 1000000000000000000
void exgcd(int a, int b, int &x, int &y)
{
	if(!b) { x = 1, y = 0; return; }
	exgcd(b, a % b, y, x);
	y -= a / b * x;
}

int inv(int x, int p)
{
	int res, tmp;
	exgcd(x, p, res, tmp);
	res = (res % p + p) % p;
	// printf("inv(%d %d) = %d\n", x, p, res);
	return res;
}

int calc(int n, int m, int p, int pk)
{
	int a = 0, b = 0, c = 0, res = 1;
	res = 1ll * res * f(n, p, pk, a) % pk;
	res = 1ll * res * invv[id][f(m, p, pk, b)] % pk;
	res = 1ll * res * invv[id][f(n - m, p, pk, c)] % pk;
	if(a - b - c >= k_[id]) return 0;
	res = 1ll * res * poww[id][a - b - c] % pk;
	return res;
}

int prime[1000], primek[1000], tot, val[1000];
int exlucas(int n, int m, int P)
{
	if(n < 0 || m < 0 || n < m) return 0;
	int res = 0;
	for(int i = 1; i <= tot; i++) id = i, val[i] = calc(n, m, prime[i], primek[i]);
	for(int i = 1; i <= tot; i++) res = (res + 1ll * (P / primek[i]) * invv[i][P / primek[i] % primek[i]] % P * val[i] % P) % P;
	return res;
}
int mod, inv2;
int solve(int n)
{
	// memset(h, idx = -1, sizeof(h));
	// printf("C(%d %d) = %d\n", 2 * n, n, mod);
	int res = n % mod * ksm(inv2, 2 * n, mod) % mod * exlucas(2 * n, n, mod) % mod;
	return res;
}

char _ED_;
void init()
{
	debug("%.3f MB\n", abs(&_ST_ - &_ED_) / 1024.0 / 1024);
	inv2 = (mod + 1) / 2;
	int p = mod; tot = 0;
    for(int i = 2; i * i <= p; i++) if(!(p % i))
    {
        prime[++tot] = i, primek[tot] = 1;
		while(!(p % i)) primek[tot] *= i, p /= i, k_[tot]++;
    }
	if(p != 1) ++tot, prime[tot] = primek[tot] = p;
	for(int i = 1; i <= tot; i++)
	{
		pre[i].push_back(1);
		invv[i].push_back(1);
		poww[i].push_back(1);
		for(int j = 1; j < primek[i]; j++)
			pre[i].push_back(1ll * pre[i].back() * (j % prime[i] ? j : 1) % primek[i]),
			invv[i].push_back(inv(j, primek[i])),
			poww[i].push_back(1ll * poww[i].back() * prime[i] % primek[i]);
	}
}


#ifdef int
	#undef int
#endif
}

// int main()
// {
// 	freopen("tmp.in", "r", stdin);
// 	freopen("tmp.out", "w", stdout);
// 	uvu::mian(); return 0;
// }

void init (int o, int p)
{
	uvu::mod = p;
	uvu::init();
	return;
}
int ask (long long n)
{
	return uvu::solve(n);
}

详细

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 119ms
memory: 26488kb

input:

1 910276 554767
6
10
7
4
10
12
9
3
3
5
7
10
5
6
1
6
3
9
6
8
12
11
8
2
12
5
9
3
8
2
12
11
2
3
4
9
2
5
5
11
6
4
8
11
3
9
2
2
8
9
2
8
9
6
2
9
2
10
10
7
5
6
4
4
11
12
8
8
2
2
4
3
3
5
6
6
8
11
6
9
9
3
4
1
2
2
6
9
9
2
3
2
12
6
1
7
2
4
12
11
4
7
6
3
9
4
6
5
3
3
12
6
2
1
1
7
2
6
5
9
11
6
3
4
11
1
2
4
5
4
10...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

wrong answer 1st numbers differ - expected: '5419', found: '0'

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Wrong Answer

Test #5:

score: 0
Wrong Answer
time: 30ms
memory: 20220kb

input:

3 1 334547
8234

output:

0

result:

wrong answer 1st numbers differ - expected: '179079', found: '0'

Subtask #4:

score: 0
Skipped

Dependency #3:

0%

Subtask #5:

score: 0
Skipped

Dependency #4:

0%

Subtask #6:

score: 0
Time Limit Exceeded

Test #8:

score: 0
Time Limit Exceeded

input:

6 958477 522361
280121915553826833
734266539148641647
72849162479700582
274266741463686096
60278972064195458
828423669427600612
571432949203039978
518511460268700898
486268614705621285
19216283231217074
611458416727512530
175147354285288662
799769622289998997
400123443628688299
145546980862133838
40...

output:

Unauthorized output

result:


Subtask #7:

score: 0
Skipped

Dependency #3:

0%

Subtask #8:

score: 0
Wrong Answer

Test #33:

score: 0
Wrong Answer
time: 47ms
memory: 7932kb

input:

8 9963 251
831797004675585320
494759973681332858
701341496127272302
252910460485222469
250965009655458584
366193481309061299
633134388675839346
791999098066205672
196620805863610860
363773642045280947
466508590762410710
407790578717064135
181590911404670570
570642047249889864
70138464625729452
23634...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

wrong answer 25th numbers differ - expected: '204', found: '0'

Subtask #9:

score: 0
Skipped

Dependency #1:

0%