线段树点更新+反素数+poj2777
来源:互联网 发布:国内外大数据公司 编辑:程序博客网 时间:2024/05/17 03:26
反素数:对于任何正整数x,其约数的个数记做g(x).例如g(1)=1,g(6)=4.如果某个正整数x满足:对于任意i(0<i<x),都有g(i)<g(x),则称x为反素数。
思路:打表,线段树维护区间空位数。
#include<iostream>#include<cstdio>#include<cstring>#include<vector>#include<cmath>#include<string>#include<queue>#include<stack>#include<map>#include<set>#include<algorithm>using namespace std;const int antiprime[36] = {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};const int factor[36] = {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};const int maxn=500010;char name[maxn][15];int a[maxn];int N,K;struct IntervalTree{ int sum[maxn<<3]; void build(int o,int l,int r) { sum[o]=r-l+1; if(l==r)return; int mid=(l+r)>>1; build(o<<1,l,mid); build(o<<1|1,mid+1,r); } void update(int o,int l,int r,int pos,int x) { if(l==r) { sum[o]+=x; return ; } int mid=(l+r)>>1; if(pos<=mid)update(o<<1,l,mid,pos,x); else update(o<<1|1,mid+1,r,pos,x); sum[o]=sum[o<<1]+sum[o<<1|1]; } int query(int o,int l,int r,int x) { if(sum[o]==x&&l==r)return l; int mid=(l+r)>>1; if(sum[o<<1]>=x)return query(o<<1,l,mid,x); return query(o<<1|1,mid+1,r,x-sum[o<<1]); }}tree;int main(){ //freopen("in.txt","r",stdin); while(scanf("%d%d",&N,&K)!=EOF) { for(int i=1;i<=N;i++) scanf("%s%d",name[i],&a[i]); tree.build(1,1,N); int step=0,pos; for(int i=0;i<36;i++) if(antiprime[i]<=N) { step=antiprime[i]; pos=i; } int cur=K,x=K; tree.update(1,1,N,K,-1); for(int i=1;i<step;i++) { int ans; if(a[x]>0)ans=(cur+a[x]-2)%(N-i)+1; else ans=((cur+a[x]-1)%(N-i)+(N-i))%(N-i)+1; if(!ans)ans=1; x=tree.query(1,1,N,ans); tree.update(1,1,N,x,-1); cur=ans; } printf("%s %d\n",name[x],factor[pos]); } return 0;}
0 0
- 线段树点更新+反素数+poj2777
- poj2777(延迟更新+线段树)
- 线段树区间更新poj2777
- POJ2777(线段树区间更新+LAZY)
- POJ2777 Count Color 线段树区间更新
- POJ2777 Count Color 线段树区间更新
- 【POJ2777】Count Color-线段树区间更新
- 线段树 + 反素数 poj2886
- poj2886 线段树+反素数
- poj2886线段树+反素数
- 线段树模板 poj2777
- POJ2777---线段树
- 线段树-POJ2777
- POJ2777(线段树)
- poj2777线段树
- poj2777 线段树
- poj2777(线段树)
- POJ2777线段树....
- ArcGIS教程:TIN 和栅格相互转换的工作原理
- JAVA构建器Builder模式
- spring技术内幕4-IoC容器解析Bean定义资源并注册解析后的Bean
- 获取dom对象中select的显示文本值和value值
- List,Set,Map用法以及区别
- 线段树点更新+反素数+poj2777
- C++类模版
- Linux各种文本编辑器查看行号的方法
- 共享桌面下+jenkins slave配置
- Cocos2d-html5入门之2048游戏
- 搬家-写在小伙伴们散伙之前@20140515
- 求子数组的最大和
- 07hibernate hibernate的ID生成策略
- Thinking in Java 笔记(四)