QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#61858#4495. Shinobu loves tripqinjianbinWA 1194ms76960kbC++1.7kb2022-11-15 18:02:322022-11-15 18:02:33

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-11-15 18:02:33]
  • 评测
  • 测评结果:WA
  • 用时:1194ms
  • 内存:76960kb
  • [2022-11-15 18:02:32]
  • 提交

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<<5];
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=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()
{
	int t=1;
	scanf("%d",&t);
	for(;t;t--)
	{
		standing_by();
		complete();
	}
	return 0;
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 1194ms
memory: 76960kb

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:

475
516
500
527
503
511
501
474
500
490
511
491
492
482
453
484
502
489
523
532
484
516
493
514
478
509
502
477
505
487
498
475
517
532
490
505
491
541
508
482
522
491
486
488
495
518
506
482
475
488
494
518
505
472
487
483
489
488
500
526
526
514
494
494
500
462
498
492
505
526
465
489
506
486
499
...

result:

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