QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#43285#4495. Shinobu loves tripBobWangWA 164ms3324kbC++1.4kb2022-08-08 20:05:242022-08-08 20:05:27

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-08-08 20:05:27]
  • 评测
  • 测评结果:WA
  • 用时:164ms
  • 内存:3324kb
  • [2022-08-08 20:05:24]
  • 提交

answer

#include<cstdio>
#include<cstring>
#include<algorithm>
#define ll long long
#define maxn 1005
#define maxt 200005
using namespace std;

struct node
{
	ll st;
	int d;
}po[maxn];
const int mt=200000;
ll p,a,s[maxt],x[maxn];
int t,n,q,tot;
int ans[maxn];

bool cmp(node x,node y)
{
	return x.d<y.d;
}

ll mul(ll x,ll y)
{
	ll ret=1;
	while(y)
	{
		if(y&1)
		ret=(ret*x)%p;
		x=(x*x)%p;
		y>>=1;
	}
	return ret;
}

ll inv(ll x)
{
	return mul(x,p-2);
}

int search(ll x)
{
	int l=0,r=tot;
	while(l<r)
	{
		int mid=(l+r)>>1;
		if(s[mid]==x)
		return 1;
		if(s[mid]>x)
		r=mid-1;
		else l=mid+1;
	}
	if(s[l]==x||s[r]==x)
	return 1;
	else return 0;
}

void solve()
{
	for(int i=1;i<=n;++i)//按照天数从小到大枚举计划
	{
		while(tot<po[i].d)
		{
			tot++;
			s[tot]=(s[tot-1]*a)%p;
		}
		for(int j=1;j<=q;++j)
		{
			if(x[j]==0)
			continue;
			if(search((x[j]*po[i].st)%p))
			ans[j]++;
		}
	}
}

int main()
{
	s[0]=1;
	scanf("%d",&t);
	while(t--)
	{
		int cnt=0;
		tot=0;
		memset(ans,0,sizeof(ans));
		scanf("%lld%lld%d%d",&p,&a,&n,&q);
		for(int i=1;i<=n;++i)
		{
			scanf("%lld%d",&po[i].st,&po[i].d);
			if(po[i].st==0)
			cnt++;
			else
			po[i].st=inv(po[i].st);
		}
		sort(po+1,po+1+n,cmp);
		for(int i=1;i<=q;++i)
		scanf("%lld",&x[i]);
		solve();
		for(int i=1;i<=q;++i)
		{
			if(x[i]!=0)
			printf("%d\n",ans[i]);
			else printf("%d\n",cnt);
		}
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 164ms
memory: 3324kb

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...

output:

1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

wrong answer 1st lines differ - expected: '167', found: '1'