bzoj4415: [Shoi2013]发牌
早上听见一大群疯子说什么树状数组上二分的乱七八糟东西
简化一下题意这题就是在牌堆里找第k张牌嘛
#include<cstdio> #include<cstring> #include<cstdlib> #include<algorithm> #include<cmath> using namespace std; int n,s[710000]; int lowbit(int x) { return x&-x; } void change(int x,int k) { while(x<=n) { s[x]+=k; x+=lowbit(x); } } int Bin[30]; int findk(int k) { int x=0,sum=0; for(int i=22;i>=0;i--) if(x+Bin[i]<=n&&sum+s[x+Bin[i]]<k) sum+=s[x+Bin[i]], x+=Bin[i]; x++;change(x,-1); return x; } int main() { Bin[0]=1;for(int i=1;i<=25;i++)Bin[i]=Bin[i-1]*2; scanf("%d",&n); for(int i=1;i<=n;i++)change(i,1); int now=1,R; for(int i=n;i>=1;i--) { scanf("%d",&R); now=(now+R)%i;if(now==0)now+=i; printf("%d\n",findk(now)); } return 0; }
pain and happy in the cruel world.