求救!最后两个点超时T-T
查看原帖
求救!最后两个点超时T-T
894556
Causality_楼主2024/8/15 15:07
#include<bits/stdc++.h>
using namespace std;
struct node{
	int data;
	node *next;
}a[1000005];
node *p;
int q,n=1;
node* serch(int x){
    node *p=&a[1];
    while(p->next!=NULL){
        if(p->data==x) break;
        p=p->next;
    }
    return p;
}
void insert(int x,int y){
    node* p=serch(x);
    a[++n]={y, p->next};
    p->next=&a[n];
}
void Delete(int x){
    node *p=serch(x);
    if(p==NULL||p->next==NULL)return;
    p->next=p->next->next; 
}
int main(){
	cin>>q;
	a[1]={1,NULL};
    int op,x,y;
    while(q--){
        cin>>op>>x;
        if(op==1){
            cin>>y;
			insert(x, y);
        }else if(op==2){
            node *p=serch(x);
            if(p==NULL||p->next==NULL)x=0;
            else  x=p->next->data;
            cout<<x<<endl;
        }else if(op==3){
            Delete(x);
        }
    }
}
2024/8/15 15:07
加载中...