QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#107141#6399. Classic: Classical Problemw4p3rWA 2ms3452kbC++204.5kb2023-05-20 14:22:432023-05-20 14:22:47

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-05-20 14:22:47]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:3452kb
  • [2023-05-20 14:22:43]
  • 提交

answer

#include<bits/stdc++.h>
#define inf 1e9
#define eps 1e-8
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define REP(i,a,b) for(int i=a;i>=b;i--)
#define pa pair<int,int>
#define pb push_back
#define fr first
#define sd second
#define db double
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
inline ll read()
{
	char ch = getchar();
	ll s = 0, w = 1;
	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;
}
vector<int> A, B, r;
int limit, l = 1;
const int mod = 998244353;
int ksm(int a, int b)
{
	int ans = 1;
	while (b) {if (b & 1)ans = 1LL * ans * a % mod; b >>= 1; a = 1LL * a * a % mod;}
	return ans;
}
int ksm(int a, int b, int mod)
{
	int ans = 1;
	while (b) {if (b & 1)ans = 1LL * ans * a % mod; b >>= 1; a = 1LL * a * a % mod;}
	return ans;
}
void NTT(vector<int>&a, int type)
{
	FOR(i, 0, limit - 1)if (i < r[i])swap(a[i], a[r[i]]);
	for (int mid = 1; mid < limit; mid <<= 1)
	{
		int wn = ksm(3, (mod - 1) / (mid << 1)); if (type < 0)wn = ksm(wn, mod - 2);
		for (int j = 0, R = (mid << 1); j < limit; j += R)
		{
			for (int k = 0, w = 1; k < mid; k++, w = 1LL * w * wn % mod)
			{
				int x = a[j + k], y = 1LL * a[j + k + mid] * w % mod;
				a[j + k] = (x + y) % mod, a[j + k + mid] = (x + mod - y) % mod;
			}
		}
	}
	if (type < 0) {int inv = ksm(limit, mod - 2); FOR(i, 0, limit - 1)a[i] = 1LL * a[i] * inv % mod;}
}

vector<int> operator *(const vector<int>&a, const vector<int>&b)
{
	int p = a.size(), q = b.size();
	limit = 1, l = 0;
	while (limit <= p + q)limit <<= 1, l++;
	A.assign(limit, 0); B.assign(limit, 0); r.assign(limit, 0);
	FOR(i, 0, limit - 1)r[i] = (r[i >> 1] >> 1) | ((i & 1) << (l - 1));
	FOR(i, 0, limit - 1)if (i < p)A[i] = a[i]; else A[i] = 0;
	FOR(i, 0, limit - 1)if (i < q)B[i] = b[i]; else B[i] = 0;
	NTT(A, 1); NTT(B, 1);
	FOR(i, 0, limit - 1)A[i] = 1LL * A[i] * B[i] % mod;
	NTT(A, -1);
	vector<int>c(limit, 0);
	FOR(i, 0, limit - 1)c[i] = A[i];
	return c;
}
vector<int> operator +(const vector<int>a, const vector<int>b)
{
	vector<int>c; int n = a.size(), m = b.size();
	c.resize(max(n, m));
	FOR(i, 0, max(n, m) - 1)
	{
		int p = (i < n ? a[i] : 0), q = (i < m ? b[i] : 0);
		c[i] = (p + q) % mod;
	}
	return c;
}
vector<int> operator -(const vector<int>a, const vector<int>b)
{
	vector<int>c; int n = a.size(), m = b.size();
	c.resize(max(n, m));
	FOR(i, 0, max(n, m) - 1)
	{
		int p = (i < n ? a[i] : 0), q = (i < m ? b[i] : 0);
		c[i] = (p + mod - q) % mod;
	}
	return c;
}
vector<int> operator *(const int a, vector<int>b)
{
	int n = b.size();
	FOR(i, 0, n - 1)b[i] = 1LL * b[i] * a % mod;
	return b;
}
vector<int> INV(const vector<int>a)
{
	vector<int>b(1, 0); b[0] = ksm(a[0], mod - 2);
	int now = 1, n = a.size();
	while (now < n)
	{
		vector<int>p = a; p.resize(min((now << 1) + 1, n));
		b = 2 * b - p * b * b; now <<= 1; b.resize(now + 1);
	}
	return b;
}

vector<int> ksm(vector<int>a, int b)
{
	vector<int>ans = a; b--;
	while (b) {if (b & 1)ans = ans * a; b >>= 1; a = a * a;}
	return ans;
}
vector<int>g, f, ans;
int g0;
int n, p;
void pre(int p)
{
	vector<int>d;
	FOR(i, 2, (p - 2))
	{
		if ((p - 1) % i == 0)d.pb(i);
	}
	FOR(i, 2, p)
	{
		int fl = 1;
		for (int x : d)if (ksm(i, x, p) == 1)fl = 0;
		if (fl) {g0 = i; break;}
	}
	// cout<<"EE:"<<p<<" "<<g0
	g.assign(p, 0); f.assign(p, 0);
	int w = 1;
	FOR(i, 0, p - 2)
	{
		g[i] = w; f[w] = i;
		w = 1LL * w * g0 % p;
	}
}
int ck(int k, const vector<int>&G)
{
	vector<int>a(p, 0), b(p, 0);
	int n = G.size() - 1;
	FOR(i, 1, n)if (G[i])a[p - 1 - f[G[i]]] = 1;
	FOR(i, 1, k)b[f[i]] = 1;
	a = a * b;
	ans.assign(p, 0); int mx = 0;
	int m = a.size();
	FOR(i, 0, m - 1)ans[g[i % (p - 1)]] += a[i];
	FOR(i, 1, p - 1)mx = max(mx, ans[i]);
	return (mx >= k);
}
void sol()
{
	n = read(), p = read();
	pre(p);
	vector<int>a(n + 1, 0), vst(p, 0);
	FOR(i, 1, n)a[i] = read(), vst[a[i]] = 1;
	if (!vst[0]) {cout << "1 1\n0\n"; return ;}
	int l = 1, r = p - 1, answer = 1;
	while (l <= r)
	{
		int mid = (l + r) >> 1;
		if (ck(mid, a))answer = mid, l = mid + 1;
		else r = mid - 1;
	}
	// cerr << "GG:" << endl;
	ck(answer, a);
	vector<int>G;
	FOR(i, 1, p - 1)if (ans[i] >= answer)G.pb(i);
	int ansm = G.size();
	cout << ansm << ' ' << answer + 1 << '\n';
	for (int x : G)cout << x << ' '; cout << '\n';

}
int main()
{
	int T = read();
	while (T--) sol();
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 2ms
memory: 3396kb

input:

3
2 3
0 2
3 5
2 3 4
3 5
0 2 3

output:

1 2
2 
1 1
0
2 2
2 3 

result:

ok 6 lines

Test #2:

score: -100
Wrong Answer
time: 2ms
memory: 3452kb

input:

3
1 2
0
1 2
1
2 2
1 0

output:

0 2

1 1
0
1 2
1 

result:

wrong answer 1st lines differ - expected: '2 1', found: '0 2'