水题……拿个变量维护一下当前牌堆顶是第几个,然后就是求第k个并删除
上来写了个Splay结果T了……粘了大爷的输出优化也不过,改成权值线段树,A了……
#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<ctime>
#include<algorithm>
#include<iomanip>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define MAXN 700010
#define MAXM 1010
#define ll long long
#define INF 1000000000
#define MOD 1000000007
#define eps 1e-8
char xB[1<<15],*xS=xB,*xT=xB;
#define getc() (xS==xT&&(xT=(xS=xB)+fread(xB,1,1<<15,stdin),xS==xT)?0:*xS++)
inline int read(){
char ch=getc();
int f=1,x=0;
while(!(ch>='0'&&ch<='9')){if(ch=='-')f=-1;ch=getc();}
while(ch>='0'&&ch<='9'){x=x*10+(ch-'0');ch=getc();}
return x*f;
}
class OStream{
private:
static const int _L=1<<15;
char stack[30];int top;
char buffer[_L],*S;
public:
OStream()
{
S=buffer;
}
void Put(int x)
{
stack[++top]='\n';
if(!x) stack[++top]='0';
else while(x)
stack[++top]=x%10+'0',x/=10;
while(top)
{
if(S==buffer+_L)
{
fwrite(buffer,1,_L,stdout);
S=buffer;
}
*S++=stack[top--];
}
}
~OStream()
{
*S=0;
fwrite(buffer,1,S-buffer,stdout);
}
}os;
int n;
int v[MAXN<<2];
inline void ud(int x){
v[x]=v[x<<1]+v[x<<1|1];
}
void get(int x,int y,int z,int p){
if(y==z){
os.Put(y);
v[x]--;
return ;
}
int mid=y+z>>1;
if(v[x<<1]>=p){
get(x<<1,y,mid,p);
}else{
get(x<<1|1,mid+1,z,p-v[x<<1]);
}
ud(x);
}
void build(int x,int y,int z){
v[x]=z-y+1;
if(y==z){
return ;
}
int mid=y+z>>1;
build(x<<1,y,mid);
build(x<<1|1,mid+1,z);
}
int main(){
int i;
n=read();
build(1,1,n);
int wzh=1;
int N=n;
while(n){
i=read();
wzh=(wzh+i-1)%n+1;
get(1,1,N,wzh);
n--;
}
return 0;
}
/*
*/