This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/**Lucky Boy**/
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define FORD(i, a, b) for (int i = (a); i >= (b); --i)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define maxc 1000000007
#define maxn 500005
#define maxm 500005
#define pii pair <int,int>
#define Task "Doktor"
template <typename T> inline void read(T &x){char c;bool nega=0;while((!isdigit(c=getchar()))&&(c!='-'));if(c=='-'){nega=1;c=getchar();}x=c-48;while(isdigit(c=getchar())) x=x*10+c-48;if(nega) x=-x;}
template <typename T> inline void writep(T x){if(x>9) writep(x/10);putchar(x%10+48);}
template <typename T> inline void write(T x){if(x<0){putchar('-');x=-x;}writep(x);putchar(' ');}
template <typename T> inline void writeln(T x){write(x);putchar('\n');}
using namespace std;
int n,a[maxn << 1],ans,sum[maxn << 1],l,r;
vector <int> b[maxn << 1];
int main()
{
//freopen(Task".inp", "r",stdin);
//freopen(Task".out", "w",stdout);
read(n);
FOR(i,1,n)
{
int x;
read(x);
a[2*i - 1] = 2 * x - 1;
}
n = 2 * n - 1;
FOR(i,1,n)
{
sum[i] = sum[i-1] + (a[i] == i);
if (i & 1) b[(a[i] + i) / 2].pb(abs(a[i] - i) / 2);
}
FOR(i,1,n) sort(b[i].begin(),b[i].end());
FOR(i,1,n)
{
FOR(j,0,(int) b[i].size() - 1)
{
int v = b[i][j];
int cur = j + 1 + sum[i - v - 1] + sum[n] - sum[i + v];
if (cur > ans)
{
ans = cur;
l = i - v,
r = i + v;
}
}
}
write((a[l] + 1) / 2);
write((a[r] + 1) / 2);
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |