QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#62412 | #4596. Ironforge | qinjianbin | RE | 0ms | 0kb | C++17 | 2.4kb | 2022-11-18 20:08:31 | 2022-11-18 20:08:32 |
Judging History
answer
#include<cstdio>
#include<iostream>
#include<set>
#define mid ((l+r)>>1)
const int maxn = 2e5+5;
using namespace std;
int n,m;
int a[maxn],b[maxn];
int theRight[maxn];
int prime[maxn],cntP;
int rk[maxn];
bool notPrime[maxn];
int theFirst[maxn],thePower[maxn];
int stk[maxn],sTop;
set<int> qhy[maxn];
void get_prime()
{
int i,j;
for(i=2;i<maxn;i++)
{
if (!notPrime[i])
{
prime[++cntP]=i;
rk[i]=cntP;
theFirst[i]=i;
thePower[i]=i;
}
for(j=1;j<=cntP&&prime[j]*i<maxn;j++)
{
notPrime[i*prime[j]]=true;
if (i%prime[j])
{
theFirst[i*prime[j]]=prime[j];
thePower[i*prime[j]]=prime[j];
}else {
theFirst[i*prime[j]]=theFirst[i];
thePower[i*prime[j]]=thePower[i]*prime[j];
break;
}
}
}
}
struct stType
{
int lp,rp,cnt;
}st[maxn];
int root[maxn];
int cntST;
int toLeft[maxn],toRight[maxn];
void add_st(int &x,int l,int r,int p)
{
if (x==0) x=++cntST;
st[x].cnt++;
if (l==r) return;
if (p<=mid) add_st(st[x].lp,l,mid,p);
else add_st(st[x].rp,mid+1,r,p);
}
int sum_st(int x,int l,int r,int L,int R)
{
if (x==0||r<L||l>R) return 0;
if (l>=L&&r<=R) return st[x].cnt;
return sum_st(st[x].lp,l,mid,L,R)+sum_st(st[x].rp,mid+1,r,L,R);
}
void standing_by()
{
int i,j;
scanf("%d%d",&n,&m);
for(i=1;i<=n;i++)
{
scanf("%d",&a[i]);
for(j=a[i];j!=1;j=j/thePower[j])
{
add_st(root[theFirst[j]],1,n,i);
}
}
for(i=1;i<n;i++) scanf("%d",&b[i]);
stk[sTop=1]=i;
theRight[n]=n;
for(i=n-1;i>=1;i--)
{
j=i;
while (j<n)
{
if (sum_st(root[b[j]],1,n,i,j))
{
j=theRight[stk[sTop]];
sTop--;
}
}
theRight[i]=j;
stk[++sTop]=i;
}
toLeft[1]=1;
toRight[1]=theRight[1];
int tmpL,tmpR;
for(i=2;i<=n;i++)
{
if (toRight[i-1]>=i)
{
if (sum_st(root[b[i-1]],1,n,i,theRight[i]))
{
toLeft[i]=toLeft[i-1];
toRight[i]=toRight[i-1];
}else {
toLeft[i]=i;
toRight[i]=theRight[i];
}
}else {
tmpL=tmpR=i;
while (tmpR<=n)
{
if (sum_st(root[b[tmpL-1]],1,n,tmpL,tmpR))
{
//v
}
}
}
}
}
void complete()
{
int i;
int x,y;
for(i=1;i<=m;i++)
{
scanf("%d%d",&x,&y);
if (toLeft[x]<=y&&toRight[x]>=y)
{
puts("Yes");
}else {
puts("No");
}
}
}
int main()
{
int t;
scanf("%d",&t);
get_prime();
for(;t;t--)
{
standing_by();
complete();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Runtime Error
input:
3 199997 200000 4147 247 11 1 19 1 11 11 13 19 377 377 4147 319 19 11 13 29 13 1 19 13 11 6061 13 143 551 4147 247 13 29 6061 13 319 377 2717 29 11 247 319 551 247 29 19 551 11 13 377 29 377 19 1 2717 247 1 29 11 1 19 143 29 11 377 143 4147 2717 4147 247 7163 1 209 551 13 1 1 551 13 143 209 143 13 1...