#include #include #include #include #include int n, q; std::map m; int main() { freopen("treefarm.in","r",stdin); freopen("treefarm.out","w",stdout); std::ios::sync_with_stdio(false); std::cin.tie(NULL); std::cout.tie(NULL); std::cin >> n; for (int i = 0; i < n; ++i) { int64_t h; std::cin >> h; m[h] = i; } std::cin >> q; for (int i = 0; i < q; ++i) { int type; int64_t h1, h2; std::cin >> type; if (type == 1) { // Question std::cin >> h1 >> h2; auto prev = m.lower_bound(h1); auto it = prev; std::advance(it, 1); int64_t hDiff = (1LL<<60); int posDiff; for (; it != m.upper_bound(h2); ++it) { if (it->first - prev->first < hDiff) { hDiff = it->first - prev->first; posDiff = std::abs(it->second - prev->second); } else if (it->first - prev->first == hDiff) { posDiff = std::min(posDiff, std::abs(it->second - prev->second)); } prev = it; } if (hDiff != (1LL<<60)) { std::cout << hDiff << ' ' << posDiff << std::endl; } else { std::cout << "-1 -1" << std::endl; } } else if (type == 2) { // insert std::cin >> h1; m[h1] = n; ++n; } else { // Erase std::cin >> h1 >> h2; auto low = m.lower_bound(h1); auto high = m.upper_bound(h2); m.erase(low, high); } } }