168242025-05-13 18:13:41vargaviviInverziócpp17Elfogadva 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;
}
RészfeladatÖsszpontTesztVerdiktIdőMemória
base50/50
1Elfogadva0/01ms316 KiB
2Elfogadva0/06ms564 KiB
3Elfogadva1/11ms508 KiB
4Elfogadva2/21ms316 KiB
5Elfogadva7/71ms316 KiB
6Elfogadva2/26ms564 KiB
7Elfogadva2/257ms2356 KiB
8Elfogadva2/257ms2356 KiB
9Elfogadva2/259ms2356 KiB
10Elfogadva2/259ms2356 KiB
11Elfogadva2/257ms2356 KiB
12Elfogadva2/256ms2548 KiB
13Elfogadva2/256ms2360 KiB
14Elfogadva2/257ms2356 KiB
15Elfogadva2/254ms2356 KiB
16Elfogadva2/257ms2356 KiB
17Elfogadva2/257ms2356 KiB
18Elfogadva2/254ms2356 KiB
19Elfogadva3/356ms2356 KiB
20Elfogadva3/354ms2548 KiB
21Elfogadva2/254ms2356 KiB
22Elfogadva2/257ms2356 KiB
23Elfogadva2/257ms2356 KiB
24Elfogadva2/254ms2172 KiB