Submission #82230

# Submission time Handle Problem Language Result Execution time Memory
82230 2018-10-29T14:47:17 Z luciocf Doktor (COCI17_doktor) C++14
60 / 100
290 ms 39532 KB
#include <bits/stdc++.h>

using namespace std;

const int maxn = 5e5+10;

int n, num[maxn], soma[maxn];
vector<int> pos[2*maxn];

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

	cin >> n;

	for (int i = 1; i <= n; i++)
	{
		cin >> num[i];
		if (num[i] == i) soma[i] = soma[i-1]+1;
		else soma[i] = soma[i-1];

		pos[num[i]+i].push_back(i);
	}

	int anss = 0, ind1 = num[1], ind2 = num[2];

	for (int i = 1; i <= n; i++)
	{
		if (num[i] < i) continue;

		int aux = soma[i-1]+soma[n]-soma[num[i]]+pos[num[i]+i].size();

		int ini = 0, fim = pos[num[i]+i].size()-1, ans = -1;

		while (ini <= fim)
		{
			int mid = (ini+fim)>>1;

			if (pos[num[i]+i][mid] >= i) fim = mid-1;
			else ans = mid, ini = mid+1;
		}

		aux -= (ans+1);

		ini = 0, fim = pos[num[i]+i].size()-1, ans = pos[num[i]+i].size();

		while (ini <= fim)
		{
			int mid = (ini+fim)>>1;

			if (pos[num[i]+i][mid] <= num[i]) ini = mid+1;
			else ans = mid, fim = mid-1;
		}
		
		aux -= (pos[num[i]+i].size()-ans);

		if (aux > anss)
		{
			anss = aux;
			ind1 = num[i], ind2 = num[num[i]];
		}
	}

	for (int i = 1; i <= n; i++)
	{
		if (num[i] > i) continue;

		int aux = soma[n]-soma[i]+soma[num[i]-1];

		int ini = 0, fim = pos[num[i]+i].size()-1, ans = -1;

		while (ini <= fim)
		{
			int mid = (ini+fim)>>1;

			if (pos[num[i]+i][mid] >= num[i]) fim = mid-1;
			else ans = mid, ini = mid+1;
		}

		aux -= (ans+1);

		ini = 0, fim = pos[num[i]+i].size()-1, ans = pos[num[i]+i].size();

		while (ini <= fim)
		{
			int mid = (ini+fim)>>1;

			if (pos[num[i]+i][mid] <= i) ini = mid+1;
			else ans = mid, fim = mid-1;
		}

		aux -= (pos[num[i]+i].size()-ans);

		if (aux > anss)
		{
			anss = aux;
			ind1 = num[num[i]], ind2 = num[i];
		}
	}

	cout << ind1 << " " << ind2 << "\n";
}
# Verdict Execution time Memory Grader output
1 Correct 23 ms 23800 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 24052 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 24052 KB Output is correct
2 Correct 23 ms 24052 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 24192 KB Output is correct
2 Incorrect 24 ms 24192 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 25 ms 24308 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 24 ms 24308 KB Output is correct
2 Incorrect 23 ms 24308 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 27 ms 24408 KB Output is correct
2 Correct 108 ms 28364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 64 ms 28364 KB Output is correct
2 Correct 56 ms 28364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 290 ms 39532 KB Output is correct
2 Correct 171 ms 39532 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 158 ms 39532 KB Output isn't correct
2 Halted 0 ms 0 KB -