2点TLE 求助orz
查看原帖
2点TLE 求助orz
1361890
_bromi_sakura楼主2025/7/26 15:25
#include<bits/stdc++.h>
using namespace std;

struct Node{
	int data;
	Node* next;
};
int main(){
	int q;
	cin>>q;
	Node* head=NULL,*tail=NULL,*ptr=NULL;
	Node stat={1,(Node*)NULL};
	head=tail=ptr=&stat;
	while(q--){
		int ope;
		cin>>ope;
		if(ope==1){
			int x,y;
			cin>>x>>y;
			Node* newp=new Node;
			newp->data=y;
			ptr=head;
			while(ptr){
				if(ptr->data==x){
					newp->next=ptr->next;
					ptr->next=newp;
					break;
				}
				ptr=ptr->next;
			}
		}else if(ope==2){
			int x;
			cin>>x;
			ptr=head;
			while(ptr){
				if(ptr->data==x){
					if(ptr->next==NULL){
						cout<<0<<endl;
					}else{
						cout<<ptr->next->data<<endl;
					}
					break;
				}
				ptr=ptr->next;
			}
		}else if(ope==3){
			int x;
			cin>>x;
			ptr=head;
			while(ptr){
				if(ptr->data==x){
					if(ptr->next==NULL){
						break;
					}else{
						Node* p=ptr->next;
						ptr->next=ptr->next->next;
						delete p;
					}
					break;
				}
				ptr=ptr->next;
			}
		}
	}

	return 0;
}
2025/7/26 15:25
加载中...