ALingyyds @ 2024-09-09 17:58:04
#include<iostream>
#include<cstdlib>
using namespace std;
typedef struct node{
int y;
int date;
node* next;
}node;
node* creatl(){
node* head=(node*)malloc(sizeof(node));
head->next=NULL;
return head;
}
node* creatnode(int date,int y){
node* newnode=(node*)malloc(sizeof(node));
newnode->y=y;
newnode->date=date;
newnode->next=NULL;
return newnode;
}
void insert(node* head,int date,int y){
node* newnode=creatnode(date,y);
newnode->next=head->next;
head->next=newnode;
}
void deletenode(node* head,int y){
node* t=head;
int k=0;
while(t->y!=y){
t=t->next;
k++;
}
k--;
node* pnode=head;
for(int i=1;i<=k;i++)
pnode=pnode->next;
pnode->next=t->next;
}
void find(node* head,int y){
node* t=head;
while(t->y!=y)
t=t->next;
cout<<t->date<<endl;
}
int n,q,i;
int main(){
node* a[100010];
cin>>n>>q;
for(i=1;i<=n;i++)
a[i]=creatl();
for(i=1;i<=q;i++){
int t,x,y,z;
cin>>t>>x>>y;
if(t==1){
cin>>z;
if(z!=0){
insert(a[x],z,y);
}
else{
deletenode(a[x],y);
}
}
if(t==2){
find(a[x],y);
}
}
return 0;
}
by _lxc__ @ 2024-09-09 17:59:35
可以用数组模拟吧 (链表太麻烦了
by 玉树临风英俊潇洒 @ 2024-09-09 18:07:40
@ ALingyyds
用map就可以了(AC
#include<bits/stdc++.h>
using namespace std;
map<long long,int>b;
long long i,j,n,q,p,k;
int main()
{
cin>>n>>q;
while(q--)
{
cin>>p>>i>>j;
if(p==1)scanf("%d",&k),b[i*1000000+j]=k;
else cout<<b[i*1000000+j]<<'\n';
}
return 0;
}
by 玉树临风英俊潇洒 @ 2024-09-09 18:07:59
@ALingyyds