QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#470817 | #6399. Classic: Classical Problem | UESTC_DECAYALI# | WA | 31ms | 8624kb | C++17 | 3.4kb | 2024-07-10 16:35:12 | 2024-07-10 16:35:14 |
Judging History
answer
#include<cstdio>
#include<iostream>
#include<vector>
#include<algorithm>
#define RI register int
#define CI const int&
using namespace std;
const int N=200005;
typedef unsigned long long u64;
int t,n,p,a[N],inv[N],vis[N],cnt,pri[N],pw[N],rev[N],c[N<<1],lst[N<<1];
struct Bitset
{
vector <u64> a;
inline Bitset(CI N=0)
{
a=vector <u64> ((N>>6)+1,0ull);
}
inline void set(CI x)
{
a[x>>6]|=(1ull<<(x&63));
}
inline int get(CI x)
{
return (a[x>>6]>>(x&63))&1;
}
inline bool empty()
{
for (RI i=0;i<a.size();++i) if (a[i]) return 0; return 1;
}
inline u64& operator [] (CI x)
{
return a[x];
}
inline const u64& operator [] (CI x) const
{
return a[x];
}
inline int size(void)
{
return a.size();
}
friend inline Bitset operator & (const Bitset& A,const Bitset& B)
{
Bitset C(p); for (RI i=0;i<C.size();++i) C[i]=A[i]&B[i]; return C;
}
};
inline int quick_pow(int x,int mod,int p,int mul=1)
{
for (;p;p>>=1,x=1LL*x*x%mod) if (p&1) mul=1LL*mul*x%mod; return mul;
}
inline void init(CI n)
{
for (RI i=2,j;i<=n;++i)
{
if (!vis[i]) pri[++cnt]=i;
for (j=1;j<=cnt&&i*pri[j]<=n;++j)
if (vis[i*pri[j]]=1,i%pri[j]==0) break;
}
}
inline vector <int> resolve(int x)
{
vector <int> vec;
for (RI i=1;i<=cnt&&1LL*pri[i]*pri[i]<=x;++i)
if (x%pri[i]==0)
{
vec.push_back(pri[i]);
while (x%pri[i]==0) x/=pri[i];
}
if (x>1) vec.push_back(x);
return vec;
}
inline int get_root(CI p)
{
vector <int> frac=resolve(p-1);
for (RI i=2;i<=p;++i)
{
bool flag=1;
for (auto x:frac)
if (quick_pow(i,p,(p-1)/x)==1)
{
flag=0; break;
}
if (flag) return i;
}
return -1;
}
int main()
{
//freopen("F.in","r",stdin);
for (scanf("%d",&t),init(200000);t;--t)
{
RI i,j; for (scanf("%d%d",&n,&p),i=1;i<=n;++i)
if (scanf("%d",&a[i]),a[i]) inv[i]=quick_pow(a[i],p,p-2);
bool ext_zero=0; for (i=1;i<=n;++i) if (a[i]==0) ext_zero=1;
if (!ext_zero) { puts("1 1\n0"); continue; }
if (n==p)
{
printf("%d %d\n",p-1,p);
for (i=1;i<p;++i) printf("%d ",i); putchar('\n');
continue;
}
if (p<=1000)
{
Bitset pre(p); for (i=0;i<pre.size();++i) pre[i]=-1ull;
bool flag=0; for (i=1;i<p;++i)
{
Bitset cur(p);
for (j=1;j<=n;++j) if (a[j]) cur.set(1LL*i*inv[j]%p);
cur=cur⪯
if (cur.empty())
{
vector <int> ans;
for (j=0;j<p;++j) if (pre.get(j)) ans.push_back(j);
printf("%d %d\n",ans.size(),i);
for (auto x:ans) printf("%d ",x); putchar('\n');
flag=1; break;
}
pre=cur;
}
if (!flag)
{
vector <int> ans;
for (j=0;j<p;++j) if (pre.get(j)) ans.push_back(j);
printf("%d %d\n",ans.size(),p);
for (auto x:ans) printf("%d ",x); putchar('\n');
}
} else
{
int g=get_root(p);
for (pw[0]=i=1;i<p-1;++i) pw[i]=1LL*pw[i-1]*g%p;
for (i=0;i<p-1;++i) rev[pw[i]]=i;
for (i=0;i<2*(p-1);++i) c[i]=0;
for (i=1;i<=n;++i) if (a[i])
c[rev[a[i]]]=c[rev[a[i]]+p-1]=1;
for (lst[2*(p-1)-1]=c[2*(p-1)-1],i=2*(p-1)-2;i>=0;--i)
if (!c[i]) lst[i]=0; else lst[i]=lst[i+1]+1;
int mx=0; for (i=0;i<2*(p-1);++i) mx=max(mx,lst[i]);
vector <int> ans;
for (i=0;i<p-1;++i) if (lst[i]==mx) ans.push_back(pw[p-1-i]);
sort(ans.begin(),ans.end());
printf("%d %d\n",ans.size(),mx+1);
for (auto x:ans) printf("%d ",x); putchar('\n');
}
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 2ms
memory: 4888kb
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: 0ms
memory: 4916kb
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: 0
Accepted
time: 0ms
memory: 6612kb
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
output:
3 1 0 1 2 1 1 0 1 2 1 1 1 0 1 2 2 1 1 0 2 3 1 2
result:
ok 14 lines
Test #4:
score: 0
Accepted
time: 1ms
memory: 4932kb
input:
31 1 5 0 1 5 1 2 5 1 0 1 5 2 2 5 0 2 2 5 2 1 3 5 1 0 2 1 5 3 2 5 0 3 2 5 1 3 3 5 0 1 3 2 5 3 2 3 5 0 2 3 3 5 2 1 3 4 5 2 0 1 3 1 5 4 2 5 4 0 2 5 1 4 3 5 1 4 0 2 5 2 4 3 5 2 4 0 3 5 4 2 1 4 5 1 0 4 2 2 5 4 3 3 5 0 4 3 3 5 3 1 4 4 5 1 4 3 0 3 5 4 3 2 4 5 2 4 0 3 4 5 2 1 4 3 5 5 1 3 0 2 4
output:
5 1 0 1 2 3 4 1 1 0 1 2 1 1 1 0 1 2 3 1 1 0 1 3 1 1 1 0 1 2 2 1 1 0 1 3 2 1 1 0 2 2 2 3 1 1 0 1 4 1 1 1 0 1 2 4 1 1 0 2 2 1 4 1 1 0 1 3 3 1 1 0 1 4 3 1 1 0 1 3 4 1 1 0 1 4 2 1 1 0 1 4 4 1 1 0 4 5 1 2 3 4
result:
ok 62 lines
Test #5:
score: 0
Accepted
time: 2ms
memory: 6616kb
input:
127 1 7 0 1 7 1 2 7 1 0 1 7 2 2 7 2 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1 0 2 3 1 6 1 1 0 2 2 3 4 1 1 0 3 2 1 3 4 1 1 0 1 3 6 1 1 0 1 5 1 1 1 0 1 2 9 1 1 0 2 2 1 9 1 1 0 2 2 6 9 1 1 0 1 3 1 1 1 0 ...
result:
ok 4094 lines
Test #7:
score: 0
Accepted
time: 8ms
memory: 4720kb
input:
8191 1 13 0 1 13 1 2 13 0 1 1 13 2 2 13 2 0 2 13 2 1 3 13 2 1 0 1 13 3 2 13 0 3 2 13 1 3 3 13 1 0 3 2 13 2 3 3 13 2 0 3 3 13 3 1 2 4 13 1 3 2 0 1 13 4 2 13 4 0 2 13 4 1 3 13 0 1 4 2 13 2 4 3 13 0 2 4 3 13 2 4 1 4 13 0 1 4 2 2 13 3 4 3 13 3 0 4 3 13 4 1 3 4 13 4 1 0 3 3 13 4 2 3 4 13 3 2 0 4 4 13 3 4...
output:
13 1 0 1 2 3 4 5 6 7 8 9 10 11 12 1 1 0 1 2 1 1 1 0 1 2 7 1 1 0 1 3 1 1 1 0 1 2 9 1 1 0 2 2 1 9 1 1 0 2 2 7 9 1 1 0 1 4 1 1 1 0 1 2 10 1 1 0 2 2 1 10 1 1 0 1 3 7 1 1 0 2 3 1 7 1 1 0 2 2 9 10 1 1 0 3 2 1 9 10 1 1 0 1 3 7 1 1 0 1 5 1 1 1 0 1 2 8 1 1 0 2 2 1 8 1 1 0 2 2 7 8 1 1 0 1 3...
result:
ok 16382 lines
Test #8:
score: 0
Accepted
time: 11ms
memory: 4736kb
input:
11764 1 17 0 1 17 1 2 17 0 1 1 17 2 2 17 0 2 2 17 2 1 3 17 2 1 0 1 17 3 2 17 3 0 2 17 1 3 3 17 3 0 1 2 17 2 3 3 17 0 3 2 3 17 3 2 1 4 17 3 2 0 1 1 17 4 2 17 0 4 2 17 4 1 3 17 1 4 0 2 17 4 2 3 17 0 2 4 3 17 2 1 4 4 17 2 4 1 0 2 17 3 4 3 17 3 4 0 3 17 4 1 3 4 17 4 1 0 3 3 17 2 4 3 4 17 2 0 3 4 4 17 2 ...
output:
17 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 1 1 0 1 2 1 1 1 0 1 2 9 1 1 0 1 3 1 1 1 0 1 2 6 1 1 0 2 2 1 6 1 1 0 2 2 6 9 1 1 0 1 4 1 1 1 0 1 2 13 1 1 0 2 2 1 13 1 1 0 1 3 9 1 1 0 2 3 1 9 1 1 0 2 2 6 13 1 1 0 3 2 1 6 13 1 1 0 1 3 9 1 1 0 1 5 1 1 1 0 1 2 7 1 1 0 2 2 1 7 1 1 0 2 2 7 ...
result:
ok 23528 lines
Test #9:
score: 0
Accepted
time: 10ms
memory: 6692kb
input:
10526 1 19 0 1 19 1 2 19 0 1 1 19 2 2 19 2 0 2 19 2 1 3 19 0 2 1 1 19 3 2 19 0 3 2 19 3 1 3 19 1 0 3 2 19 3 2 3 19 2 0 3 3 19 1 3 2 4 19 1 2 0 3 1 19 4 2 19 0 4 2 19 4 1 3 19 0 1 4 2 19 4 2 3 19 4 0 2 3 19 2 4 1 4 19 4 2 0 1 2 19 4 3 3 19 0 3 4 3 19 1 3 4 4 19 3 4 0 1 3 19 4 3 2 4 19 0 4 3 2 4 19 1 ...
output:
19 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 1 1 0 1 2 1 1 1 0 1 2 10 1 1 0 1 3 1 1 1 0 1 2 13 1 1 0 2 2 1 13 1 1 0 2 2 10 13 1 1 0 1 4 1 1 1 0 1 2 5 1 1 0 2 2 1 5 1 1 0 1 3 10 1 1 0 2 3 1 10 1 1 0 2 2 5 13 1 1 0 3 2 1 5 13 1 1 0 1 3 10 1 1 0 1 5 1 1 1 0 1 2 4 1 1 0 2 2 1 4 ...
result:
ok 21052 lines
Test #10:
score: 0
Accepted
time: 6ms
memory: 6636kb
input:
10000 9 83 60 35 63 59 58 81 0 13 71 1 5 0 1 7 0 2 61 39 0 2 7 0 4 1 7 0 2 19 0 14 1 2 0 3 23 14 10 0 3 11 0 5 2 1 5 0 2 7 0 4 2 3 0 2 2 3 0 1 1 13 0 5 47 10 2 34 15 0 1 2 0 1 17 0 1 11 0 2 7 1 0 1 7 0 2 23 0 17 2 13 10 0 2 7 1 0 6 31 19 13 6 29 0 24 4 23 0 5 18 17 2 19 0 5 1 7 0 2 13 7 0 3 17 0 6 1...
output:
2 3 38 76 5 1 0 1 2 3 4 7 1 0 1 2 3 4 5 6 1 2 36 1 2 2 7 1 0 1 2 3 4 5 6 1 2 15 2 1 0 1 2 2 5 7 2 2 6 9 5 1 0 1 2 3 4 1 2 2 1 2 2 1 2 1 13 1 0 1 2 3 4 5 6 7 8 9 10 11 12 4 2 18 22 24 33 2 1 0 1 17 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 11 1 0 1 2 3 4 5 6 7 8 9 10 1 2 1 7 1 0 ...
result:
ok 20000 lines
Test #11:
score: 0
Accepted
time: 31ms
memory: 4664kb
input:
10000 10 11 6 8 0 1 7 3 2 9 4 5 21 23 21 19 10 17 11 20 6 3 2 18 9 16 13 14 4 12 8 7 1 0 15 7 7 6 2 4 0 1 5 3 17 19 4 6 5 11 17 15 0 10 3 8 12 18 13 7 9 2 14 15 17 11 15 8 2 12 3 1 13 16 6 7 0 9 10 5 2 2 0 1 2 2 0 1 33 37 11 20 9 16 19 32 33 31 3 29 36 10 8 25 22 17 5 6 15 28 14 0 4 27 18 12 34 21 3...
output:
1 10 1 1 19 4 6 7 1 2 3 4 5 6 1 14 14 1 14 12 1 2 1 1 2 1 2 21 21 24 1 8 8 6 7 1 2 3 4 5 6 10 11 1 2 3 4 5 6 7 8 9 10 1 22 22 1 6 1 1 10 11 1 26 22 2 3 1 2 1 14 16 22 23 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 2 4 2 6 1 18 3 6 7 1 2 3 4 5 6 1 2 1 1 8 7 1 28 15...
result:
ok 20000 lines
Test #12:
score: 0
Accepted
time: 12ms
memory: 6132kb
input:
10000 4 13 4 5 0 6 12 31 0 16 11 13 3 24 26 21 20 6 5 19 12 43 29 21 40 23 31 24 27 17 30 10 0 42 3 3 0 2 1 15 47 41 46 0 44 17 39 30 4 12 14 36 28 27 31 10 1 5 0 5 11 6 2 0 5 1 6 13 11 0 7 5 10 6 5 17 15 0 9 12 11 6 13 0 5 2 12 11 7 15 43 14 28 13 24 40 29 37 9 27 0 34 39 15 12 2 1 3 0 8 17 15 6 0 ...
output:
3 2 8 10 11 1 6 6 2 3 33 41 2 3 1 2 3 3 31 37 41 5 1 0 1 2 3 4 2 3 1 2 2 3 4 8 4 2 2 8 10 14 1 3 12 1 4 14 3 1 0 1 2 1 4 8 2 1 0 1 3 2 4 9 10 4 2 1 3 5 12 1 2 3 5 2 3 12 15 16 18 7 1 0 1 2 3 4 5 6 5 2 2 5 15 16 18 10 2 2 6 8 11 19 25 27 29 34 35 3 2 2 7 9 1 2 2 3 3 7 14 15 2 ...
result:
ok 20000 lines
Test #13:
score: 0
Accepted
time: 17ms
memory: 6632kb
input:
10000 13 19 13 6 0 9 15 2 4 10 3 5 11 12 14 5 11 5 8 10 0 6 2 3 0 1 1 2 0 10 19 6 16 2 1 17 0 4 10 5 7 4 7 0 1 4 2 41 73 55 47 13 35 18 68 3 25 67 36 70 69 62 37 56 64 49 72 12 0 4 17 31 8 66 63 2 16 65 60 24 26 7 21 33 52 54 39 29 53 71 1 3 0 26 61 43 0 37 54 47 49 17 38 19 28 35 18 39 36 33 34 8 2...
output:
1 6 13 2 3 7 9 1 2 1 2 1 0 1 1 4 10 3 3 1 2 4 1 12 72 3 1 0 1 2 2 5 10 17 1 7 11 1 7 27 1 4 8 2 3 1 2 2 3 1 2 1 2 1 1 2 2 1 6 6 1 8 31 1 4 13 1 3 3 1 4 12 3 5 1 2 7 1 7 5 1 2 4 3 1 0 1 2 2 1 0 1 2 4 4 6 1 2 4 2 2 1 10 2 4 10 12 2 4 4 6 1 2 2 2 6 3 5 7 1 0 1 2 3 4 5 6...
result:
ok 20000 lines
Test #14:
score: 0
Accepted
time: 21ms
memory: 6908kb
input:
10000 2 3 0 2 38 61 50 55 35 52 17 40 15 51 39 11 5 41 2 33 49 25 0 24 53 13 30 59 9 34 57 37 38 27 29 1 19 31 46 8 45 58 6 42 11 17 5 13 1 11 2 0 6 7 4 12 10 6 11 3 0 4 7 10 6 21 29 17 14 7 18 20 28 23 25 16 3 22 5 21 2 0 9 13 1 12 11 19 5 5 0 3 2 1 4 20 23 19 16 0 1 15 18 14 12 21 6 22 8 11 13 20 ...
output:
1 2 2 2 10 15 45 1 7 3 1 5 8 2 8 7 24 4 5 1 2 3 4 1 14 20 1 9 16 1 6 7 1 7 29 1 6 6 2 2 1 4 1 6 8 1 3 4 2 4 2 3 1 8 5 1 7 8 2 4 1 3 1 6 3 1 9 14 1 6 5 1 2 1 2 7 11 22 1 8 12 2 5 2 8 2 6 3 10 1 7 2 1 4 2 1 2 1 1 4 1 1 5 11 1 14 28 2 3 1 2 1 2 1 1 10 8 1 8 6 1 6 5 ...
result:
ok 20000 lines
Test #15:
score: 0
Accepted
time: 25ms
memory: 6008kb
input:
10000 17 17 1 5 10 2 16 6 12 13 15 3 8 9 11 4 14 7 0 67 67 34 11 54 25 8 40 33 24 2 44 22 5 28 46 23 59 30 1 38 18 55 15 35 6 39 64 27 51 65 12 52 53 58 20 14 19 29 43 0 9 62 45 41 42 47 49 31 32 26 57 37 48 7 36 17 13 10 50 63 3 16 21 4 61 66 56 60 3 3 1 0 2 3 3 2 0 1 5 5 4 0 2 1 3 13 13 8 1 5 10 4...
output:
16 17 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 66 67 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 2 3 1 2 2 3 1 2 4 5 1 2 3 4 12 13 1 2 3 4 5 6 7 8 9 10 ...
result:
ok 20000 lines
Test #16:
score: -100
Wrong Answer
time: 5ms
memory: 8624kb
input:
1000 2 11 0 1 23 173 145 124 4 130 41 45 115 53 102 156 68 85 49 100 114 75 0 90 81 96 93 61 91 37 293 0 206 166 68 220 15 58 256 125 182 239 67 116 32 114 261 8 106 137 89 130 120 128 202 75 2 110 5 233 133 145 74 259 164 264 10 56 19 181 18 165 71 52 170 177 81 114 124 46 103 20 43 94 144 96 0 125...
output:
1 2 1 2 3 50 60 1 4 176 18 2 27 38 42 44 45 51 52 58 66 80 94 100 122 127 147 148 171 172 5 2 3 9 13 23 33 1 3 126 3 3 101 318 624 1 3 16 1 3 60 8 2 8 10 24 31 32 38 39 44 1 3 35 8 2 17 19 24 44 51 59 61 69 5 3 44 95 108 126 216 6 3 82 100 284 471 479 501 2 3 276 298 5 3 72 181 186 19...
result:
wrong answer 501st lines differ - expected: '9 3', found: '14 3'