Question
这题新加了一个插入操作,然后就是询问了,还好没有修改。。。
网上的大都是什么vector的,都是STL。。。(但是身为蒟蒻的我还不会STL(┭┮﹏┭┮))
所以我就将这输入用指针来存,然后插入就找到l的位置,然后指针插入。
反正都是随机数据嘛~(应该不会遇到特殊情况)
就这样我卡过了。。。
上标:
#include<cstdio>
#include<cmath>
#define N 200010
#define M 2010
using namespace std;
int n,a[N],hav[M],tail[M],nx[N],st,m=1,now,p;
int opt,l,r,c;
inline int read()
{
int x=0,f=0; char c=getchar();
while (c<'0' || c>'9') f=(c=='-') ? 1:f,c=getchar();
while (c>='0' && c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
return f ? -x:x;
}
int main()
{
freopen("6282.in","r",stdin);
freopen("6282.out","w",stdout);
n=read(),st=sqrt(n);tail[m]=1;
for (int i=1,j=0;i<=n;i++,j++)
{
a[i]=read();
if (j==st) tail[++m]=i,j=0;
else nx[i-1]=i;
hav[m]++;
}
for (int i=n;i;i--)
{
opt=read(),l=read(),r=read(),c=read();
if (opt==0)
{
now=1;
while (hav[now]<l) l-=hav[now++];
if (--l)
{
p=tail[now],l--;
while (l) p=nx[p],l--;
nx[++n]=nx[p],nx[p]=n;
}
else nx[++n]=tail[now],tail[now]=n;
a[n]=r,hav[now]++;
}
else
{
now=1;
while (hav[now]<r) r-=hav[now++];
p=tail[now];r--;
while (r) p=nx[p],r--;
printf("%d
",a[p]);
}
}
return 0;
}