QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#61863#4495. Shinobu loves tripqinjianbinAC ✓1613ms77012kbC++1.7kb2022-11-15 18:08:412022-11-15 18:08:42

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:08:42]
  • 评测
  • 测评结果:AC
  • 用时:1613ms
  • 内存:77012kb
  • [2022-11-15 18:08:41]
  • 提交

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;
}

詳細信息

Test #1:

score: 100
Accepted
time: 1613ms
memory: 77012kb

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:

167
166
168
168
174
169
2
167
169
22
153
169
150
163
7
152
149
166
166
176
63
178
125
170
94
167
155
173
56
147
163
169
167
183
78
165
179
173
182
170
166
150
152
166
169
169
169
173
162
52
180
182
170
163
173
173
175
150
171
166
170
148
170
166
63
168
172
151
150
72
129
14
61
167
167
169
174
133
17...

result:

ok 5000 lines