QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#61860 | #4495. Shinobu loves trip | qinjianbin | RE | 0ms | 0kb | C++ | 1.7kb | 2022-11-15 18:05:30 | 2022-11-15 18:05:33 |
Judging History
answer
#include<cstdio>
#include<set>
#include<iostream>
#define mid ((l+r)>>1)
#define lx (x<<1)
#define rx (x<<1|1)
using namespace std;
const int maxn =2e5+5;
typedef long long LL;
int P,n,a,q;
struct stType
{
int lp,rp,cnt;
} st[maxn<<6];
int rt[maxn];
int cntST;
int s[maxn],d[maxn];
LL qpow(LL x,LL y)
{
LL res=1;
for(;y;y>>=1,x=x*x%P)
if (y&1) res=res*x%P;
return res;
}
void add_st(int &x,int l,int r,int p)
{
st[++cntST]=st[x];
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);
}
void standing_by()
{
int i;
LL pw;
scanf("%d%d%d%d",&P,&a,&n,&q);
add_st(rt[0],1,P,1);
pw=a;
for(i=1;i<maxn;i++)
{
rt[i]=rt[i-1];
if (pw!=1)
{
//printf("orz %d\n",pw);
add_st(rt[i],1,P,pw);
pw=pw*a%P;
}
}
//printf("%d\n",cntST);
for(i=1;i<=n;i++)
{
scanf("%d%d",&s[i],&d[i]);
s[i]=qpow(s[i],P-2);
}
}
int get_cnt(int x,int l,int r,int p)
{
if (x==0) return 0;
if (l==r) return st[x].cnt;
if (p<=mid) return get_cnt(st[x].lp,l,mid,p);
else return get_cnt(st[x].rp,mid+1,r,p);
}
void complete()
{
int i,x,y;
int ans;
for(;q;q--)
{
ans=0;
scanf("%d",&x);
for(i=1;i<=n;i++)
{
if (s[i]&&x)
{
y=1ll*s[i]*x%P;
//printf("qhy%d\n",y);
if (get_cnt(rt[d[i]],1,P,y)) ans++;
else {
// printf("%d Nothing\n",i);
}
}else {
if (x==s[i]) ans++;
}
}
printf("%d\n",ans);
}
for(i=1;i<=cntST;i++) st[i].cnt=st[i].lp=st[i].rp=0;
cntST=0;
for(i=1;i<maxn;i++) rt[i]=0;
}
int main()
{
freopen("orz.in","r",stdin);
int t=1;
scanf("%d",&t);
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:
5 999999937 4628 1000 1000 162585517 24584 407438671 108585 46973547 132178 142179754 23710 198067620 130706 829852550 190969 676555968 2127 717426372 80994 332054419 1078 471194333 66473 105470508 154839 939339406 89663 73289403 90982 529133484 198011 526081635 28219 405427868 174742 120011816 6408...