#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) ;
if(ans > opt) opt = ans, O = {L, R};
}
cout<<v[O.f]<<" "<<v[O.s]<<"\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
26 ms |
23928 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
27 ms |
23932 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
28 ms |
24040 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
26 ms |
24180 KB |
Output is correct |
2 |
Correct |
26 ms |
24180 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
26 ms |
24256 KB |
Output is correct |
2 |
Correct |
27 ms |
24256 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
26 ms |
24256 KB |
Output is correct |
2 |
Correct |
27 ms |
24256 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
29 ms |
24400 KB |
Output is correct |
2 |
Correct |
131 ms |
30912 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
74 ms |
30912 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
291 ms |
43096 KB |
Output is correct |
2 |
Correct |
167 ms |
43096 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
158 ms |
43096 KB |
Output is correct |
2 |
Correct |
121 ms |
46820 KB |
Output is correct |