poj2886(线段树更新约瑟夫环)

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
#include<queue>
#include<set>
#define mem(a,x) memset(a,x,sizeof(a))
#define s1(x) scanf("%d",&x)
#define s2(x,y) scanf("%d%d",&x,&y)
#define s3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define s4(x,y,z,k) scanf("%d%d%d%d",&x,&y,&z,&k)
#define ff(a,n) for(int i = 0 ; i < n; i++) scanf("%d",a+i)
#define tp(x) printf("x = %d\n",x)
#define ansp(x) printf("%d\n",x)
//inline ll ask(int x){ll res=0;while(x)res+=c[x],x-=x&(-x);return res;}
//inline void add(int x,int d){while(x<=n)c[x]+=d,x+=x&(-x);}
#define ls 2*rt
#define rs 2*rt+1
#define lson ls,L,mid
#define rson rs,mid+1,R
#define ll long long
using namespace std;
typedef pair<int,int> pii;
const ll inf = 0x3f3f3f3f;


const int antiprime[]={1,2,4,6,12,24,36,48,60,120,180,240,360,720,840,
                       1260,1680,2520,5040,7560,10080,15120,20160,25200,
                       27720,45360,50400,55440,83160,110880,166320,221760,
                       277200,332640,498960,554400,665280
                      };
 
const int factorNum[]={1,2,3,4,6,8,9,10,12,16,18,20,24,30,32,36,40,48,60,
                       64,72,80,84,90,96,100,108,120,128,144,160,168,180,
                       192,200,216,224};


const int mx = 5e5+10;
int node[mx<<2];
int n,k,pos,mod; 
struct no{
	char name[13];
	int id;
}p[mx];
void build(int rt, int L, int R){
	node[rt] = R-L+1;
	if(L == R)
		return;
	int mid = (L+R)/2;
	build(lson);
	build(rson);
}
int update(int rt, int L, int R, int p){
	node[rt]--;
	if(L == R)
		return L;
	int mid = (L+R)/2;
	if(p <= node[ls])
		return update(lson, p);
	else
		return update(rson, p-node[ls]);
	
}
int main(){
	//int T=10;	scanf("%d",&T);
	//	freopen("F:\\in.txt","r",stdin);
	while(s2(n,k) != EOF){
		for(int i = 1; i <= n ; i++){
			scanf("%s%d",p[i].name,&p[i].id);
		}
		int cnt = 0;
		while(cnt<35&&antiprime[cnt] <= n)
			cnt++;
		cnt--;
		
		p[0].id = 0;
		 pos = 0;
		 build(1,1,n);                         //忘了建树, ,,,, 
		for(int i = 0; i < antiprime[cnt]; i++){
			mod = node[1];                           //mod应该被更新的 
			if(p[pos].id > 0)
				k = ((k+p[pos].id-2)%mod+mod)%mod+1; //错写成减号  
			else{
				k = ((k+p[pos].id-1)%mod+mod)%mod+1;
			}
			pos = update(1,1,n,k); 
		}
		printf("%s %d\n",p[pos].name,factorNum[cnt]);
	}


	return 0;
}

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Blaze Jack

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值