Files
luogu/P10466.cpp
T
hanyixuanten c5eebf5252
Check cpp / md pair / Check md headers (push) Successful in 4s
new file: P10466.cpp
2026-11-02 07:15:21 +00:00

26 lines
597 B
C++

#include <bits/stdc++.h>
using namespace std;
set<int> s;
map<int, int> rev;
int n;
int tmp;
int main(void) {
scanf("%d%d", &n, &tmp), s.insert(tmp), rev[tmp] = 1;
for(int i = 2; i <= n; i++) {
scanf("%d", &tmp), s.insert(tmp), rev[tmp] = i;
auto lb = s.lower_bound(tmp), ub = s.upper_bound(tmp);
int minval = INT_MAX, ind = 0;
if(lb != s.begin()) {
--lb;
if(abs(tmp - *lb) < minval)
minval = abs(tmp - *lb), ind = rev[*lb];
}
if(ub != s.end())
if(abs(tmp - *ub) < minval)
minval = abs(tmp - *ub), ind = rev[*ub];
printf("%d %d\n", minval, ind);
}
return 0;
}