#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<queue>
#include<stack>
#include<string>
#include<map>
#include<set>
#include<cmath>
#include<cassert>
#include<cstring>
#include<iomanip>
using namespace std;
#ifdef _WIN32
#define i64 __int64
#define out64 "%I64d\n"
#define in64 "%I64d"
#else
#define i64 long long
#define out64 "%lld\n"
#define in64 "%lld"
#endif
/************ for topcoder by zz1215 *******************/
#define FOR(i,a,b) for( int i = (a) ; i <= (b) ; i ++)
#define FFF(i,a) for( int i = 0 ; i < (a) ; i ++)
#define FFD(i,a,b) for( int i = (a) ; i >= (b) ; i --)
#define S64(a) scanf(in64,&a)
#define SS(a) scanf("%d",&a)
#define LL(a) ((a)<<1)
#define RR(a) (((a)<<1)+1)
#define pb push_back
#define CL(Q) while(!Q.empty())Q.pop()
#define MM(name,what) memset(name,what,sizeof(name))
#define read freopen("in.txt","r",stdin)
#define write freopen("out.txt","w",stdout)
const int inf = 0x3f3f3f3f;
const i64 inf64 = 0x3f3f3f3f3f3f3f3fLL;
const double oo = 10e9;
const double eps = 10e-9;
const double pi = acos(-1.0);
const int maxn = 500011;
struct zz
{
int x; // sum
int l;
int r;
}zx[maxn<<2];
struct ss
{
int h;
int x;
bool operator < (const ss & cmp ) const
{
return x<cmp.x;
}
}sd;
int n,k;
string s[maxn];
int f[maxn];
int oula[maxn];
vector<int>p;
vector<ss>fp;
vector<ss>vx;
int endpos;
int endans;
void pushup(int root)
{
zx[root].x = zx[LL(root)].x + zx[RR(root)].x;
return ;
}
void build(int l=1,int r=n,int root=1)
{
zx[root].l = l;
zx[root].r = r;
if(l==r)
{
zx[root].x=1;
return ;
}
else
{
int mid = (l+r)/2;
build(l,mid,LL(root));
build(mid+1,r,RR(root));
pushup(root);
}
return ;
}
int query(int l,int r,int root=1)
{
if(l<=zx[root].l && r>=zx[root].r)
{
return zx[root].x;
}
else
{
int re = 0;
if(LL(root)<maxn*4 && l<=zx[LL(root)].r)
{
re += query(l,r,LL(root));
}
if(RR(root)<maxn*4 && r>=zx[RR(root)].l)
{
re += query(l,r,RR(root));
}
return re;
}
}
void remove(int pos,int root=1)
{
if(zx[root].l==pos && zx[root].r == pos)
{
// assert(zx[root].x!=0);
zx[root].x = 0;
return ;
}
else
{
if(LL(root)<maxn*4 && pos<=zx[LL(root)].r)
{
remove(pos,LL(root));
}
else if(RR(root)<maxn*4 && pos>=zx[RR(root)].l)
{
remove(pos,RR(root));
}
pushup(root);
}
return ;
}
bool isp(int x)
{
for(int i=0;p[i]*p[i]<=x;i++)
{
if(x%p[i]==0)
{
return false;
}
}
return true;
}
void initp()
{
p.clear();
p.pb(2);
for(int i=3;i<100;i++)
{
if(isp(i))
{
p.pb(i);
}
}
return ;
}
void dfs(int rest,int step=0,int pre=inf,int have=1,int now=1)
{
if(now>maxn || step >= p.size() ) return ;
if(rest == 0)
{
sd.x=now;
sd.h=have;
vx.pb(sd);
return ;
}
else
{
int temp;
for(int i=min(rest,pre);i>=1;i--)
{
temp = now;
for(int u=1;u<=i;u++)
{
temp*=p[step];
if(temp>maxn) return ;
}
dfs(rest-i,step+1,i,have*(i+1),temp);
}
}
return ;
}
void init()
{
vx.clear();
fp.clear();
for(int i=0;i<30;i++)
{
dfs(i);
}
sort(vx.begin(),vx.end());
int temp=-inf;
for(int i=0;i<vx.size();i++)
{
if(vx[i].h>temp)
{
temp = vx[i].h;
fp.pb(vx[i]);
}
}
return ;
}
int find(int tx)
{
int root = 1;
while(zx[root].l!=zx[root].r)
{
if(zx[LL(root)].x>=tx)
{
root = LL(root);
}
else
{
tx-=zx[LL(root)].x;
root =RR(root);
}
}
return zx[root].l;
}
void start()
{
build();
for(int i=0;i<fp.size();i++)
{
if(n>=fp[i].x)
{
endpos = fp[i].x;
endans = fp[i].h;
}
else
{
break;
}
}
int now = k;
int temp;
int tot;
for(int i=1;i<endpos;i++)
{
remove(now);
tot=zx[1].x;
if(f[now]>0)
{
temp = query(1,now) + f[now];
temp = (temp-1)%tot+1;
temp = (temp+tot-1)%tot+1;
}
else
{
temp = query(1,now) + 1 + f[now];
temp = (temp-1)%tot+1;
temp = (temp+tot-1)%tot+1;
}
now = find(temp);
}
endpos = now;
return ;
}
int main()
{
initp();
init();
char c[15];
while(scanf("%d%d",&n,&k)!=EOF)
{
for(int i=1;i<=n;i++)
{
scanf("%s",c);
s[i] = c;
SS(f[i]);
}
start();
cout<<s[endpos]<<" "<<endans<<endl;
}
return 0;
}
分享到:
相关推荐
pku acm 2752 Seek the Name, Seek the Fame代码 kmp算法。解题报告:http://blog.csdn.net/china8848
pku acm 1050 To the Max代码,有详细注释,动态规划
Now the only thing the house misses is a cute little wooden fence. He had no idea how to make a wooden fence, so he decided to order one. Somehow he got his hands on the ACME Fence Catalogue 2002, ...
being proposed, most existing action datasets focus on the action recognition tasks for the segmented videos. There is a lack of standard large-scale benchmarks, especially for current popular data-...
pku acm 1274 The Perfect Stall 代码 二分图的最大匹配的匈牙利算法 解题报告请访问:http://blog.csdn.net/china8848
Pku acm 第1163题 The Triangle 代码,有详细的注释,动态规划
pku部分题代码,不多,试一下怎么上传文件!
pku1000 pku1000程序 解题报告
pku经典题目解题报告 pku经典题目解题报告
Pku acm 第1887题 Testing the CATCHER 代码,有详细的注释,动态规划
有一些代码是pku上的,希望大家看后给我留言,看看我的代码那里有问题??
pku1664源代码
PKU JudgeOnline FAQ 中文版 常见问题解答
8数码代码pku1077,300ms(哈希+广度搜索)
ppt word PKU 课件 五星级灰常强大
ACM代码 北大pku。 搞ACM的可以参考一下。代码还是挺规范的。有接近150道题目的代码。
我写的解题报告,关于度限制生成树的 网址:http://acm.pku.edu.cn/JudgeOnline/problem?id=1639<br>题目:Picnic Planning 来源:East Central North America 2000
PKU 2339 Rock, Scissors, Paper 源代码
pku acm 1469 COURSES 代码 二分图的最大匹配的匈牙利算法 解题报告请访问:http://blog.csdn.net/china8848
这是关于PKU上的题目分类 很详细 适合不同水平的童鞋们参考