https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1422
先预处理出前1e5个数 直接模拟这个过程 对于第二种操作用二分优化一下 看当前循环节往后覆盖的第一个数
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e5+10;
struct node1
{
int tp,x;
ll l,c;
};
struct node2
{
int id;
ll pos;
};
node1 order[maxn];
node2 query[maxn];
int ary[maxn],ans[maxn];
int m,n;
bool cmp(node2 n1,node2 n2)
{
return n1.pos<n2.pos;
}
int main()
{
ll len;
int i,j,k,l,r,mid,p;
scanf("%d",&m);
for(i=1;i<=m;i++)
{
scanf("%d",&order[i].tp);
if(order[i].tp==1) scanf("%d",&order[i].x);
else scanf("%lld%lld",&order[i].l,&order[i].c);
}
scanf("%d",&n);
for(i=1;i<=n;i++)
{
query[i].id=i;
scanf("%lld",&query[i].pos);
}
sort(query+1,query+n+1,cmp);
len=1;
for(i=1;i<=m&&len<=maxn;i++)
{
if(order[i].tp==1) ary[len++]=order[i].x;
else
{
for(j=1;j<=order[i].c&&len<=maxn;j++)
{
for(k=1;k<=order[i].l&&len<=maxn;k++)
{
ary[len++]=ary[k];
}
}
}
}
len=0,j=1;
for(i=1;i<=m;i++)
{
if(order[i].tp==1)
{
len++;
while(j<=n&&query[j].pos<=len)
{
ans[query[j].id]=order[i].x;
j++;
}
}
else
{
while(order[i].c>0)
{
l=1,r=order[i].c,p=-1;
while(l<=r)
{
mid=(l+r)/2;
if(len+mid*order[i].l<query[j].pos) l=mid+1;
else r=mid-1,p=mid;
}
if(p==-1)
{
len+=order[i].c*order[i].l;
order[i].c=0;
}
else
{
len+=p*order[i].l;
while(j<=n&&query[j].pos<=len)
{
ans[query[j].id]=ary[(query[j].pos-len+order[i].l-1+maxn)%maxn+1];
j++;
}
order[i].c-=p;
}
}
}
}
for(i=1;i<=n;i++) printf("%d ",ans[i]);
printf("\n");
return 0;
}