QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#80473 | #2637. Factor-Free Tree | OtoriEmu | WA | 98ms | 67672kb | C++14 | 1.9kb | 2023-02-23 21:57:00 | 2023-02-23 21:57:03 |
Judging History
answer
/*
¤ï¤ó¤ï¤ó¡¡¤ï¤ó¤À¤Û©`¤¤¤Ã¡î
Wonderhoy!
*/
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef double DB;
char buf[1<<21],*p1=buf,*p2=buf;
#define getchar() (p1==p2 && (p2=(p1=buf)+fread(buf,1,1<<18,stdin),p1==p2)?EOF:*p1++)
int read()
{
int x=0;
char c=getchar();
while(c<'0' || c>'9') c=getchar();
while(c>='0' && c<='9') x=(x<<1)+(x<<3)+(c^'0'),c=getchar();
return x;
}
void write(int x)
{
if(x>9) write(x/10);
putchar(x%10+'0');
}
typedef pair<int,int> P;
typedef vector<int> Poly;
typedef vector<P> PolyP;
#define mp make_pair
#define spc putchar(' ')
#define etr putchar('\n')
#define inlp(x,y) putchar(x==y?'\n':' ')
int prime[3000005],cnt;
int mnp[10000005];
bool vis[10000005];
void shai(int up)
{
vis[1]=true;
for(int i=2;i<=up;++i)
{
if(!vis[i]) prime[++cnt]=mnp[i]=i;
for(int j=1;j<=cnt && prime[j]*i<=up;++j)
{
if(!vis[prime[j]*i]) mnp[prime[j]*i]=prime[j];
vis[prime[j]*i]=true;
if(i%prime[j]==0) break;
}
}
}
int n;
int a[1000005];
int ap[10000005];
int L[1000005],R[1000005];
int fa[1000005];
int Solve(int l,int r)
{
if(l>r) return 0;
if(l==r) return l;
int rt=-1;
for(int i=l,j=r;i<=j;++i,--j)
{
if(L[i]<l && r<R[i])
{
rt=i;
break;
}
if(L[j]<l && r<R[j])
{
rt=j;
break;
}
}
if(rt==-1) exit(puts("impossible")&0);
fa[Solve(l,rt-1)]=fa[Solve(rt+1,r)]=rt;
return rt;
}
int main(){
n=read();
for(int i=1;i<=n;++i) a[i]=read();
shai(*max_element(a+1,a+1+n));
for(int i=1;i<=n;++i)
{
int w=a[i];
while(w^1) L[i]=max(L[i],ap[mnp[w]]),w/=mnp[w];
w=a[i];
while(w^1) ap[mnp[w]]=i,w/=mnp[w];
}
for(int i=1;i<=1e7;++i) ap[i]=n+1;
for(int i=n;i;--i)
{
R[i]=n+1;
int w=a[i];
while(w^1) R[i]=min(R[i],ap[mnp[w]]),w/=mnp[w];
w=a[i];
while(w^1) ap[mnp[w]]=i,w/=mnp[w];
}
Solve(1,n);
for(int i=1;i<=n;++i) write(fa[i]),inlp(i,n);
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 98ms
memory: 67672kb
input:
1000000 19 29 31 37 41 43 47 53 59 23 29 31 37 41 43 47 53 59 17 37 41 43 47 53 31 37 41 43 47 53 29 37 41 43 47 31 37 41 43 47 23 37 41 43 47 53 59 61 31 37 41 43 47 53 59 61 29 41 43 47 53 59 37 41 43 47 53 59 31 41 47 53 59 61 67 71 73 43 47 53 59 61 67 71 73 37 61 71 73 79 83 89 97 67 71 73 79 8...
output:
19 10 2 3 4 5 6 7 8 1 10 11 12 13 14 15 16 17 999895 25 20 21 22 23 31 25 26 27 28 29 41 36 32 33 34 31 36 37 38 39 999880 49 42 43 44 45 46 47 57 49 50 51 52 53 54 55 41 63 58 59 60 61 69 63 64 65 66 67 57 86 78 71 72 73 74 75 76 70 78 79 80 81 82 83 84 69 101 94 88 89 90 91 92 87 94 95 96 97 98 99...
result:
ok
Test #2:
score: 0
Accepted
time: 8ms
memory: 49700kb
input:
10 34033 56827 124799 25981 90371 129293 195581 175601 77867 102811
output:
0 1 2 3 4 5 6 7 8 9
result:
ok
Test #3:
score: 0
Accepted
time: 7ms
memory: 47768kb
input:
100 4007 58067 87683 39181 1319 17659 105871 128981 112241 153733 98419 148867 162119 3877 28627 26681 10211 64591 146701 91183 192307 179119 81283 4729 65419 143197 37649 92567 48473 31277 182141 196991 17387 47491 183499 59107 61687 21323 160079 150401 16477 92809 182561 39113 151787 83557 173293 ...
output:
0 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 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
result:
ok
Test #4:
score: -100
Wrong Answer
time: 4ms
memory: 50824kb
input:
1000 89417 156589 58309 7919 93497 100207 163981 176503 8887 69163 198823 102653 88609 13477 112603 94219 46831 34963 39113 190901 101723 121421 30553 51673 98129 17509 101021 28439 90023 16069 98299 66851 133321 587 154057 53381 67369 49277 1783 9109 7537 45137 32533 101627 137507 154789 29717 1386...
output:
0 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 59 60 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 91 89 91 92 93 94 95 96 97 98 99 100 101 10...
result:
wrong answer Team has 17 children for index 60