#include<bits/stdc++.h>
using namespace std;
struct node{
int data;
node *next = NULL;
}*head = new node;
void insert_place(int x,int a) //在第x个后面插入元素 a
{
node *now = new node;//新建元素
now->data = a;
node *pla = head;//找到数字x,需要遍历枚举
while (pla->data != x) {//一步步遍历过去 ,直到找到了对应的数
pla = pla->next;
}
now->next = pla->next;//先把新建元素的next放好
pla->next = now;//再改变其他元素的下一个位置
}
int find(int x) {//找到数x
node *pla = head;//找到第place个位置,需要遍历枚举
while (pla->data != x) {//一步步遍历过去 ,直到找到了对应的数
pla = pla->next;
}
if (pla->next == NULL) return 0;
return pla->next->data;
}
void del(int x) {//删除x
node *pla = head;//找到第place个位置,需要遍历枚举
while (pla->data != x) {//一步步遍历过去 ,直到找到了对应的数
pla = pla->next;
}
node * to_del = pla->next;//我们要删除的数是当前位置的下一个位置
pla ->next = pla->next->next;//我们当前位置的下一个位置是之前下一个位置的下一个位置。
delete to_del;//删除当前元素
}
int main(){
head->data = 1;
int q,op,x,y;
cin >> q;
while (q--) {
cin >> op;
if (op == 1) {
cin >> x >> y;
insert_place(x,y);
} else if(op == 2) {
cin >> x;
cout << find(x) << '\n';
} else {
cin >> x;
del(x);
}
}
}
#include<bits/stdc++.h>
using namespace std;
struct node{
int data;
int next;
}a[1000050];
void insert(int x,int y) {
a[y].data = y;
a[y].next = a[x].next;
a[x].next = y;
}
int find(int x) {
return a[x].next;
}
void del(int x) {
a[x].next = a[a[x].next].next;
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
int q,op,x,y;
cin >> q;
while (q--) {
cin >> op;
if (op == 1) {
cin >> x >> y;
insert(x,y);
} else if(op == 2) {
cin >> x;
cout << find(x) << '\n';
} else {
cin >> x;
del(x);
}
}
}
#include<bits/stdc++.h>
using namespace std;
int a[150][2050],ans = 1e9,ma = -1e9;
struct node{
int data;
int l,r;
const bool operator < (const node &a)const{
return data > a.data;
}
};
priority_queue<node>q;
int main(){
//ios::sync_with_stdio(0);
//cin.tie(0);cout.tie(0);
int n,m;
cin >> n >> m;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
cin >> a[i][j];
//cout << "ok\n";
}
sort(a[i] + 1, a[i] + 1 + m);
node p;
p.data = a[i][1];
p.l = i;
p.r = 1;
q.push(p);//一开始,先把最小的数先push进去
//cout << i << endl;
ma = max(a[i][1],ma);//找到枚举的最大值
}
//cout << "ok\n";
while (q.size()) {
node p = q.top();
// cout << p.l << ' ' << p.r << ' ' << p.data << endl;
q.pop();
ans = min(ma - p.data,ans);//找到当前枚举的最小值
if (p.r == m) break;
ma = max(ma, a[p.l][p.r + 1]);
node pp;
pp.data = a[p.l][p.r + 1];
pp.r = p.r + 1;
pp.l = p.l;
q.push(pp);
}
cout << ans << endl;
}