Submission #82274

# Submission time Handle Problem Language Result Execution time Memory
82274 2018-10-29T17:32:06 Z MatheusLealV Doktor (COCI17_doktor) C++17
100 / 100
312 ms 57116 KB
#include <bits/stdc++.h>
#define N 1000010
#define f first
#define s second
using namespace std;
typedef pair<int, int> pii;

pii O;

int n, a[N], v[N], opt, pref[N], suf[N];

vector<int> val[N];

int main()
{
	ios::sync_with_stdio(false); cin.tie(0);

	cin>>n;

	for(int i = 1; i <= n; i++)
	{
		cin>>v[i];

		a[v[i]] = i;

		pref[i] = pref[i - 1] + (v[i] == i);
	}

	for(int i = n; i >= 1; i--) suf[i] = suf[i + 1] + (v[i] == i);

	for(int i = 1; i <= n; i++) val[i + a[i]].push_back(i);

	for(int i = 1; i < N; i++) sort(val[i].begin(), val[i].end());

	for(int i = 1; i <= n; i++)
	{
		int L = min(i, a[i]), R = max(i, a[i]);

		int ans = upper_bound(val[i + a[i]].begin(), val[i + a[i]].end(), R) - lower_bound(val[i + a[i]].begin(), val[i + a[i]].end(), L) + suf[R + 1] + pref[L - 1];

		if(ans > opt) opt = ans, O = {L, R};
	}

	cout<<v[O.f]<<" "<<v[O.s]<<"\n";
}
# Verdict Execution time Memory Grader output
1 Correct 27 ms 23928 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 26 ms 23936 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 25 ms 23984 KB Output is correct
2 Correct 27 ms 23984 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 27 ms 24052 KB Output is correct
2 Correct 26 ms 24100 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 28 ms 24272 KB Output is correct
2 Correct 28 ms 24272 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 28 ms 24328 KB Output is correct
2 Correct 26 ms 24328 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 29 ms 24612 KB Output is correct
2 Correct 112 ms 32748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 59 ms 32748 KB Output is correct
2 Correct 53 ms 32748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 312 ms 49020 KB Output is correct
2 Correct 173 ms 49020 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 152 ms 49020 KB Output is correct
2 Correct 126 ms 57116 KB Output is correct