【分块打表】Gym - 100923K - Por Costel and the Firecracker
2017-01-20 02:01
399 查看
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
Output
因为卡内存,所以不能把答案的表全打出来,但是可以每隔100记录一次答案,这样只需要开10w的数组。然后每次询问的时候,从最近的记录的答案开始暴力,不超过100次就能得到答案。
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; }
相关文章推荐
- I - Por Costel and the Pairs Gym - 100923I _思维啊——可惜我现在还没
- 【并查集】Gym - 100923H - Por Costel and the Match
- 【数形结合】Gym - 100923I - Por Costel and the Pairs
- 【找规律】Gym - 100923L - Por Costel and the Semipalindromes
- L - Por Costel and the Semipalindromes Gym - 100923L
- 【带权并查集】Gym - 100923H - Por Costel and the Match
- 【Heap-dijkstra】Gym - 100923B - Por Costel and the Algorithm
- Por Costel and Azerah Gym - 100923A
- A - Por Costel and Azerah Gym - 100923A
- A - Por Costel and Azerah Gym - 100923A
- 【动态规划】Gym - 100923A - Por Costel and Azerah
- [杂题 交互] Codeforces Gym 101190 NEERC 16 I. Indiana Jones and the Uniform Cave
- 【 Gym - 101138J 】Valentina and the Gift Tree(树链剖分)
- Gym 101343.J - Husam and the Broken Present 2(状压dp)
- GYM 100694 L.Hanoi Towers and the Progress(dp)
- Rasheda And The Zeriba Gym - 100283A 计算几何
- The Difference Between Keypoints and Descriptors
- hdu 1027 Ignatius and the Princess II
- Custom tool error: Failed to generate code for the service reference ××××××. Please check other error and warning messages for details.
- 解决Eclipse下不自动拷贝apk到模拟器问题( The connection to adb is down, and a severe error has occured)