/**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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
22 ms |
23800 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
23 ms |
23924 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
22 ms |
23972 KB |
Output is correct |
2 |
Correct |
21 ms |
23972 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
23 ms |
24068 KB |
Output is correct |
2 |
Correct |
24 ms |
24068 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
23 ms |
24108 KB |
Output is correct |
2 |
Correct |
22 ms |
24108 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
24 ms |
24236 KB |
Output is correct |
2 |
Correct |
22 ms |
24236 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
24 ms |
24424 KB |
Output is correct |
2 |
Correct |
85 ms |
30684 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
44 ms |
30684 KB |
Output is correct |
2 |
Correct |
51 ms |
30684 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
218 ms |
43688 KB |
Output is correct |
2 |
Correct |
133 ms |
43688 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
115 ms |
43688 KB |
Output is correct |
2 |
Correct |
115 ms |
53892 KB |
Output is correct |