求助
  • 板块灌水区
  • 楼主Dr_April
  • 当前回复1
  • 已保存回复1
  • 发布时间2025/1/17 11:04
  • 上次更新2025/1/17 15:00:18
查看原帖
求助
931470
Dr_April楼主2025/1/17 11:04

下载数据后本机确认无误,但是luogu未能通过。

题目是P1110,代码是这玩意:

#include<bits/stdc++.h>
using namespace std;
#define Theresa return
#define Amiya 0
#define Scout getchar()
const int doctor=2e6+10,Vishdale=2e9+10;
inline int Rhodes(){
	int x=Amiya;char ch=Scout;
	while(ch<'0'||ch>'9')ch=Scout;
	while(ch>='0'&&ch<='9'){
		x=(x<<3)+(x<<1)+(ch^48);
		ch=Scout;
	}
	Theresa x;
}
int n,m,a[doctor];
int cnt=Amiya,root=Amiya;
struct node{
	int ls,rs,key,pri,siz;
}te[doctor];
mt19937 _rand(time(NULL));
void newnode(int x){
	te[++cnt].siz=1;te[cnt].ls=te[cnt].rs=Amiya;te[cnt].key=x;te[cnt].pri=_rand();
}
void push_up(int u){
	te[u].siz=te[te[u].ls].siz+te[te[u].rs].siz+1;
}
inline int gt_max(int u){
    while(te[u].rs)u=te[u].rs;
    return te[u].key;
}
inline int gt_min(int u){
    while(te[u].ls)u=te[u].ls;
    return te[u].key;
}
void Split(int u,int x,int &L,int &R){
	if(u==Amiya){
		L=R=Amiya;Theresa;
	}
	if(te[u].key<=x){
		L=u;Split(te[u].rs,x,te[u].rs,R);
	}
	else{
		R=u;
		Split(te[u].ls,x,L,te[u].ls);
	}
	push_up(u);
}
int mset(int L,int R){
	if(L==Amiya||R==Amiya)Theresa L+R;
	if(te[L].pri>te[R].pri){
		te[L].rs=mset(te[L].rs,R);
		push_up(L);
		Theresa L;
	}
	else{
		te[R].ls=mset(L,te[R].ls);
		push_up(R);
		Theresa R;
	}
}
int last[doctor],ans=Vishdale;
void Insert(int x){
	int L,R;
	Split(root,x,L,R);
	if(te[L].siz)ans=min(ans,min(abs(gt_min(L)-x),abs(gt_max(L)-x)));
	if(te[R].siz)ans=min(ans,min(abs(gt_min(R)-x),abs(gt_max(R)-x)));
	newnode(x);int tmp=mset(L,cnt);
	root=mset(tmp,R);
}
int del(int x){
	int L,R,p;
	Split(root,x,L,R);
	Split(L,x-1,L,p);
	p=mset(te[p].ls,te[p].rs);
	root=mset(mset(L,p),R);
}
int Rank(int x){
	int L,R;Split(root,x-1,L,R);
	int tmp=te[L].siz+1;root=mset(L,R);
	Theresa tmp;
}
int kth(int u,int k){
	if(k==te[te[u].ls].siz+1)Theresa u;
	if(k<=te[te[u].ls].siz)Theresa kth(te[u].ls,k);
	if(k>te[te[u].ls].siz)Theresa kth(te[u].rs,k-te[te[u].ls].siz-1);
}
int Pre(int x){
	int L,R,tmp;
	Split(root,x-1,L,R);tmp=te[kth(L,te[L].siz)].key;
	root=mset(L,R);Theresa tmp;
}
int Suc(int x){
	int L,R,tmp;Split(root,x,L,R);tmp=te[kth(R,1)].key;
	root=mset(L,R);Theresa tmp;
}
struct Heap{
	priority_queue<int,vector<int>,greater<int> >q1,q2;
	void insert(int x){
		q1.push(x);
	}
	void del(int x){
		q2.push(x);
	}
	int Get(){
		while(!q2.empty()&&!q1.empty()&&q2.top()==q1.top()){
			q2.pop();q1.pop();
		}
		Theresa q1.top();
	}
}heap;
struct lis{
	int pre,to,key;
}le[doctor];
int tot=n+1;
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]),Insert(a[i]),last[i]=i;
	for(int i=1;i<=n;i++)le[i].pre=i-1,le[i].to=i+1,le[i].key=a[i];
	for(int i=2;i<=n;i++)heap.insert(abs(a[i]-a[i-1]));
	tot=n+1;
	while(m--){
		char ch[8];cin>>ch;
		if(ch[Amiya]=='I'){
			int x,y;x=Rhodes();y=Rhodes();
			Insert(y);
			heap.del(abs(le[le[last[x]].to].key-le[last[x]].key));
			le[++tot].key=y;le[tot].pre=last[x];le[tot].to=le[last[x]].to;le[le[last[x]].to].pre=tot;le[last[x]].to=tot;
			heap.insert(abs(le[tot].key-le[last[x]].key));heap.insert(abs(le[le[tot].to].key-le[tot].key));last[x]=tot;
		}
		else if(ch[Amiya]=='M'&&ch[4]=='S')printf("%d\n",ans);
		else printf("%d\n",heap.Get());
	}
	Theresa Amiya;
}

输入:

10 20
33 87024675 43512354 174049319 217561644 130536998 261073969 348098617 304586294 391610940
INSERT 1 21770567
INSERT 2 174060039
INSERT 2 43514251
MIN_GAP
INSERT 2 174060043
INSERT 2 65272338
MIN_SORT_GAP
INSERT 6 152314558
INSERT 6 261101532
MIN_GAP
INSERT 6 152314554
MIN_GAP
MIN_GAP
INSERT 1 152315265
MIN_GAP
INSERT 2 152299949
MIN_SORT_GAP
MIN_GAP
INSERT 8 435123234
INSERT 5 174083729

输出:

1897
4
27563
21759984
21759984
21759984
4
21770534

本机运行结果:

https://cdn.luogu.com.cn/upload/image_hosting/ogkf6oyt.png?x-oss-process=image/resize,m_lfit,h_170,w_225

这是为什么

2025/1/17 11:04
加载中...