在luogu似乎函数递归放在最后就会咕咕咕(不确信)
by hfee @ 2019-05-02 07:25:53
写的没看出来问题,估计是递归的原因,另外这题最后一个点要开40倍才能过,~~毒瘤数据~~
by zzy2333 @ 2019-05-02 07:53:36
看出来了...最后一个query函数有可能没有返回值,加个return就好了
by zzy2333 @ 2019-05-02 07:55:54
谢谢大佬,我改成void就过了。。。
```c
#include <bits/stdc++.h>
using namespace std;
const int mac=1e6+10;
struct node
{
int ls,rs,val;
}tree[mac*20];
int a[mac],tot=0,edtor[mac]={1},ans;
int build(int l,int r)
{
int pos=++tot;
if (l==r){
tree[pos].val=a[l];
return pos;
}
int mid=(l+r)>>1;
tree[pos].ls=build(l,mid);
tree[pos].rs=build(mid+1,r);
return pos;
}
int update(int ed,int l,int r,int p,int k)
{
int pos=++tot;
if (l==r){
tree[pos].val=k;
return pos;
}
tree[pos].ls=tree[ed].ls;
tree[pos].rs=tree[ed].rs;
int mid=(l+r)>>1;
if (mid>=p) tree[pos].ls=update(tree[ed].ls,l,mid,p,k);
else tree[pos].rs=update(tree[ed].rs,mid+1,r,p,k);
return pos;
}
void query(int ed,int l,int r,int p)
{
if (l==r){
ans=tree[ed].val;
return;
}
int mid=(l+r)>>1;
if (mid>=p) query(tree[ed].ls,l,mid,p);
else query(tree[ed].rs,mid+1,r,p);
return;
}
int main()
{
//freopen("test.in","r",stdin);
int n,m;
scanf ("%d%d",&n,&m);;
for (int i=1; i<=n; i++){
scanf ("%d",&a[i]);
}
build (1,n);
int v,id,loc,val;
for (int i=1; i<=m; i++){
scanf ("%d%d%d",&v,&id,&loc);
if (id==1){
scanf ("%d",&val);
edtor[i]=update(edtor[v],1,n,loc,val);
}
else {
edtor[i]=edtor[v];
query(edtor[v],1,n,loc);
printf ("%d\n",ans);
}
}
return 0;
}
```
by 孤风 @ 2019-05-02 10:05:41