QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#127813 | #6399. Classic: Classical Problem | UNos_maricones | RE | 1ms | 3720kb | C++20 | 2.6kb | 2023-07-20 08:58:16 | 2023-07-20 08:58:18 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std ;
#define ff first
#define ss second
#define pb push_back
typedef long long ll;
typedef pair<ll,int> ii;
typedef long double lf;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
const ll SQ = 320;
const ll N = 2e5+5;
const ll mod = 998244353;
const ll oo = 1e14+5;
int powmod (int a, int b, int p) {
int res = 1;
while (b)
if (b & 1)
res = int (res * 1ll * a % p), --b;
else
a = int (a * 1ll * a % p), b >>= 1;
return res;
}
int generator (int p) {
vector<int> fact;
int phi = p-1, n = phi;
for (int i=2; i*i<=n; ++i)
if (n % i == 0) {
fact.push_back (i);
while (n % i == 0)
n /= i;
}
if (n > 1)
fact.push_back (n);
for (int res=2; res<=p; ++res) {
bool ok = true;
for (size_t i=0; i<fact.size() && ok; ++i)
ok &= powmod (res, phi / fact[i], p) != 1;
if (ok) return res;
}
return -1;
}
int main(){
#ifdef LOCAL
freopen("input.txt","r",stdin);
#endif // LOCAL
ios_base::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
int t; cin >> t;
while (t--) {
int n, p; cin >> n >> p;
int c = generator(p);
vector <int> a(n);
vector <int> ap(p);
for (auto &e : a) cin >> e, ap[e] = 1;
sort(a.begin(), a.end());
if (a[0] == 0) {
if (n == 1) {
cout << p << " 1\n";
for (int i = 0; i < p; ++i) cout << i << ' ';
cout << '\n';
}
else {
vector <int> seq;
int curre = 1;
for (int i = 0; i < p - 1; ++i) seq.pb(curre), curre = (curre * c) % p;
vector<bitset<N>> bt(p);
bitset<N> up, down;
for (int i = 0; i < p - 1; ++i) {
if (ap[seq[i]]) down[p-i]=1;
}
for (int i = 0; i < p - 1; ++i) {
up<<=1;
down>>=1;
if (ap[seq[i]]) {
down[p-1]=0;
up[0]=1;
}
bt[seq[i]] = up|down;
}
bitset<N> curr;
curr.set();
for (int i = 1; i <= p; ++i) {
if ((curr & bt[i]).any()) {
curr &= bt[i];
}
else {
cout << curr.count() << ' ' << i << '\n';
for (int j = 0; j < p; ++j) {
if (curr[j] == 1) cout << seq[j] << ' ';
}
cout << '\n';
break;
}
// cout << i << endl;
}
}
}
else {
cout << "1 1\n0\n";
}
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3680kb
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: 0
Accepted
time: 1ms
memory: 3720kb
input:
3 1 2 0 1 2 1 2 2 1 0
output:
2 1 0 1 1 1 0 1 2 1
result:
ok 6 lines
Test #3:
score: -100
Runtime Error
input:
7 1 3 0 1 3 1 2 3 1 0 1 3 2 2 3 2 0 2 3 1 2 3 3 0 1 2