# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
992476 |
2024-06-04T13:57:44 Z |
LOLOLO |
Doktor (COCI17_doktor) |
C++14 |
|
118 ms |
53864 KB |
#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[i] = v[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) + suf[R + 1] + pref[L - 1];
if(ans > opt) opt = ans, O = {L, R};
}
cout<<v[O.f]<<" "<<v[O.s]<<"\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
29272 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
29272 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
29276 KB |
Output is correct |
2 |
Correct |
5 ms |
29276 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
29272 KB |
Output is correct |
2 |
Correct |
7 ms |
29272 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
29288 KB |
Output is correct |
2 |
Correct |
8 ms |
29272 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
29316 KB |
Output is correct |
2 |
Correct |
6 ms |
29284 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
29532 KB |
Output is correct |
2 |
Correct |
53 ms |
34532 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
32088 KB |
Output is correct |
2 |
Correct |
20 ms |
30944 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
118 ms |
50260 KB |
Output is correct |
2 |
Correct |
96 ms |
41104 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
54 ms |
38732 KB |
Output is correct |
2 |
Correct |
65 ms |
53864 KB |
Output is correct |