#include #include #include #include #include using namespace std; struct Tree { long long height; long long position; bool operator<(const Tree& other) const { return height < other.height || (height == other.height && position < other.position); } }; int main() { int n; cin >> n; vector trees(n); for (int i = 0; i < n; i++) { cin >> trees[i].height; trees[i].position = i + 1; } sort(trees.begin(), trees.end()); set positions; for (int i = 0; i < n; i++) { positions.insert(trees[i].position); } int q; cin >> q; for (int i = 0; i < q; i++) { int type; cin >> type; if (type == 1) { long long l, r; cin >> l >> r; auto lower = positions.lower_bound(l); auto upper = positions.upper_bound(r); if (lower == upper) { cout << "-1 -1\n"; } else { long long minDiff = LLONG_MAX; long long minPosDiff = LLONG_MAX; auto it = lower; while (it != upper) { auto next = it; next++; if (next != upper) { long long diff = trees[*next - 1].height - trees[*it - 1].height; long long posDiff = *next - *it; if (diff < minDiff || (diff == minDiff && posDiff < minPosDiff)) { minDiff = diff; minPosDiff = posDiff; } } it = next; } cout << minDiff << " " << minPosDiff << "\n"; } } else if (type == 2) { long long hnewq; cin >> hnewq; Tree newTree; newTree.height = hnewq; newTree.position = n + 1; trees.push_back(newTree); positions.insert(newTree.position); n++; } else if (type == 3) { long long l, r; cin >> l >> r; auto it = positions.lower_bound(l); while (it != positions.end() && *it <= r) { positions.erase(it++); } } } return 0; }