This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define f first
#define s second
using namespace std;
typedef pair<int,int> ii;
ii p;
int n,a[1000005],v[1000005],tmp,pref[1000005],suf[1000005];
vector<int> val[1000005];
int main(){
ios::sync_with_stdio(false); cin.tie();cout.tie();
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<1000005;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>tmp){
tmp=ans;
p={l,r};
}
}
cout<<v[p.f]<<" "<<v[p.s];
}
# | 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... |