首页 > 其他 > 详细

【分块打表】Gym - 100923K - Por Costel and the Firecracker

时间:2017-01-20 07:24:39      阅读:306      评论:0      收藏:0      [点我收藏+]

semipal.in / semipal.out

Por Costel the pig, our programmer in-training, has recently returned from the Petrozaporksk training camp. There, he learned a lot of things: how to boil a cob, how to scratch his belly using his keyboard, etc... He almost remembers a programming problem too:

A semipalindrome is a word 技术分享 for which there exists a subword 技术分享 such that 技术分享 is a prefix of 技术分享 and 技术分享 (reverse 技术分享) is a suffix of 技术分享. For example, ‘ababba‘ is a semipalindrom because the subword ‘ab‘ is prefix of ‘ababba‘ and ‘ba‘ is suffix of ‘ababba‘.

Let‘s consider only semipalindromes that contain letters ‘a‘ and ‘b‘. You have to find the 技术分享-th lexicographical semipalindrome of length 技术分享.

Por Costel doesn‘t remember if the statement was exactly like this at Petrozaporksk, but he finds this problem interesting enough and needs your help to solve it.

Input

On the first line of the file semipal.in, there is an integer 技术分享 (技术分享) representing the number of test cases. On the next 技术分享 lines there are 2 numbers, 技术分享 (技术分享 and K 技术分享 where 技术分享 is the number of semipalindromes of length 技术分享.

Output

In the output file semipal.out, there should be 技术分享 lines, the 技术分享-th of which should contain the answer for the 技术分享-th test.

Example

Input
2
5 1
5 14
Output
aaaaa
bbabb

 

因为卡内存,所以不能把答案的表全打出来,但是可以每隔100记录一次答案,这样只需要开10w的数组。然后每次询问的时候,从最近的记录的答案开始暴力,不超过100次就能得到答案。

#include<cstdio>
using namespace std;
#define MOD 10000003
typedef long long ll;
int n,a,b,x1,q,q1;
int anss[100010];
int main()
{
	freopen("pocnitoare.in","r",stdin);
	freopen("pocnitoare.out","w",stdout);
//	freopen("k.in","r",stdin);
	scanf("%d%d%d%d%d%d",&n,&a,&b,&x1,&q,&q1);
	int now=x1;
	anss[1]=now;
	for(int i=2;i<=10000003;++i)
	  {
	  	now=(int)((((ll)now*(ll)(i-1)%(ll)n)%(ll)n+(ll)a%(ll)n)%(ll)n);
	  	if(i%100==1)
	  	  anss[i/100+1]=now;
	  }
//	int now=anss[q1/100+1];
//	int tmp=q1%100-1;
//	for(int i=1;i<=tmp;++i)
//	  now=(int)((((ll)now*(ll)(i-1)%(ll)n)%(ll)n+(ll)a%(ll)n)%(ll)n);
//	printf("%d\n",now);
	for(int i=1;i<=q;++i)
	  {
	  	if(i!=1)
	  	  q1=((int)((ll)(i-1)*(ll)now%(ll)MOD)+b%MOD)%MOD+1;
	  	now=anss[(q1-1)/100+1];
		for(int j=(q1-1)/100*100+2;j<=q1;++j)
	  	  now=(int)((((ll)now*(ll)(j-1)%(ll)n)%(ll)n+(ll)a%(ll)n)%(ll)n);
		printf("%d\n",now);
	  }
	return 0;
}

【分块打表】Gym - 100923K - Por Costel and the Firecracker

原文:http://www.cnblogs.com/autsky-jadek/p/6321747.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!