#include<bits/stdc++.h>
using namespace std;
#define x first
#define y second
typedef pair<int,int> PII;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef vector<string> VS;
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
vector<int> vx;
inline int mp(int x) {return upper_bound(vx.begin(),vx.end(),x)-vx.begin();}
inline int log_2(int x) {return 31-__builtin_clz(x);}
inline int popcount(int x) {return __builtin_popcount(x);}
inline int lowbit(int x) {return x&-x;}
void solve()
{
	int n;
	cin>>n;
	vector<int> a(n);
	set<int> s;
	map<int,int> mp; 
	for(int i=0;i<n;++i) cin>>a[i];
	s.insert(a[0]);
	mp[a[0]] = 1;
	for(int i=1;i<n;++i)
	{
		auto it = s.lower_bound(a[i]);
		int val = 2e9, pos = 1e9;
		//注意读题要求的是选Ai更小的而不是下标
		if(it!=s.end()) {auto s = *it;val = s-a[i],pos = mp[s];}
		if(it!=s.begin()) 
		{
			it--;
			auto s = *it;
			if(a[i]-s<=val) val = a[i]-s, pos = mp[s];
		}
		cout<<val<<' '<<pos<<'\n';
		
		if(mp.find(a[i])==mp.end())
		{
			s.insert(a[i]);
			mp[a[i]] = i+1;
		}
	}
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int T = 1;
	//cin>>T;
	while(T--)
	{
		solve();
	}
}

 posted on 2024-09-13 17:22  ruoye123456  阅读(7)  评论(0编辑  收藏  举报