168242025-05-13 18:13:41vargaviviInverziócpp17Accepted 50/5059ms2548 KiB
#include <bits/stdc++.h>
using namespace std;

int main() {
	/*
	//időlimites
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, hossz = 0, ans1 = -1, ans2;
    cin >> n;
	vector<pair<int, int>> v(n);
	vector<int> vege(n);
	for (int i = 0; i < n; i ++) {
		vege[i] = i;
		cin >> v[i].first;
		v[i].second = i;
	}
	sort(v.rbegin(), v.rend());
	for (int i = 0; i < n - 1; i ++) {
		if (vege.back() - v[i].second > hossz) {
			hossz = vege.back() - v[i].second;
			ans1 = v[i].second + 1;
			ans2 = vege.back() + 1;
		}
		vege.erase(find(vege.begin(), vege.end(), v[i].second));
	}
	cout << ans1 << " ";
	if (ans1 != -1) cout << ans2;
	*/
	ios::sync_with_stdio(false);
	cin.tie(0);
	/*
	int n, hossz = 0, ans1 = -1, ans2;
    cin >> n;
	int last = n - 1;
	vector<pair<int, int>> v(n);
	vector<bool> vege(n);
	for (int i = 0; i < n; i ++) {
		vege[i] = i;
		cin >> v[i].first;
		v[i].second = i;
	}
	sort(v.rbegin(), v.rend());
	for (int i = 0; i < n - 1; i ++) {
		if (last - v[i].second > hossz) {
			hossz = last - v[i].second;
			ans1 = v[i].second + 1;
			ans2 = last + 1;
		}
		vege[v[i].second] = false;
		if (last == v[i].second) {
			int index = last;
			while (index >= 0 && !vege[index]) {
				index --;
			}
			last = index;
		}
	}
	cout << ans1 << " ";
	if (ans1 != -1) cout << ans2;
	*/
	//egyszerűbb megoldás:
	int n;
	cin >> n;
	vector<int> poz(n + 1);
	for (int i = 1; i <= n; i ++) {
		int x;
		cin >> x;
		poz[x] = i;
	}
	int maxi = poz[1];
	int hossz = 0, ans1 = -1, ans2;
	for (int i = 2; i <= n; i ++) {
		if (maxi - poz[i] > hossz) {
			hossz = maxi - poz[i];
			ans1 = poz[i];
			ans2 = maxi;
		}
		maxi = max(maxi, poz[i]);
	}
	cout << ans1 << " ";
	if (ans1 != -1) cout << ans2;
}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/01ms316 KiB
2Accepted0/06ms564 KiB
3Accepted1/11ms508 KiB
4Accepted2/21ms316 KiB
5Accepted7/71ms316 KiB
6Accepted2/26ms564 KiB
7Accepted2/257ms2356 KiB
8Accepted2/257ms2356 KiB
9Accepted2/259ms2356 KiB
10Accepted2/259ms2356 KiB
11Accepted2/257ms2356 KiB
12Accepted2/256ms2548 KiB
13Accepted2/256ms2360 KiB
14Accepted2/257ms2356 KiB
15Accepted2/254ms2356 KiB
16Accepted2/257ms2356 KiB
17Accepted2/257ms2356 KiB
18Accepted2/254ms2356 KiB
19Accepted3/356ms2356 KiB
20Accepted3/354ms2548 KiB
21Accepted2/254ms2356 KiB
22Accepted2/257ms2356 KiB
23Accepted2/257ms2356 KiB
24Accepted2/254ms2172 KiB