扩展的序列超级大,显然不可能正常操作
发现不管怎么进行操作二,数字的来源一定是操作一
那是不是意味着可以进行回溯呢?
维护数组 b b b表示每次操作后序列有多少个数字
就可以进行二分啊!!
比如当前找位置x的数,在 b b b二分找到是第 i n d e x index index次操作
如果 i n d e x index index次操作是类型一,说明就是这次操作添加的那个数
否则,是通过类型二从前面赋值过来的,继续往前回溯就好了
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int maxn=2e5+10;
int n,b[maxn],m;
struct edge{
int type,li,ci;
}a[maxn];
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cin >> m;
int pl=0;
for(int i=1;i<=m;i++)
{
cin >> a[i].type ;
if( a[i].type==2 )
{
cin >> a[i].li >> a[i].ci;
pl += a[i].li*a[i].ci;
}
else
{
cin >> a[i].li;
pl++;
}
b[i] = pl;
}
cin >> n;
for(int i=1;i<=n;i++)
{
int x,index; cin >> x;
index = lower_bound(b+1,b+1+m,x)-b;
if( a[index].type==1 ) cout << a[index].li << " ";
else
{
while( 1 )
{
index = lower_bound(b+1,b+1+m,x)-b;
if( a[index].type==1 )
{
cout << a[index].li << " ";
break;
}
else
{
x -= b[index-1];
x = x % a[index].li;
if( x==0 ) x = a[index].li;
}
}
}
}
return 0;
}