Submission #235178

#TimeUsernameProblemLanguageResultExecution timeMemory
235178VimmerDoktor (COCI17_doktor)C++14
70 / 100
1093 ms8168 KiB
#include <bits/stdc++.h> #pragma GCC optimize("unroll-loops") #pragma GCC optimize("-O3") #pragma GCC optimize("Ofast") //#pragma GCC optimize("fast-math") //#pragma GCC optimize("no-stack-protector") #define F first #define S second #define sz(x) int(x.size()) #define pb push_back #define N 500001 #define M ll(1e9 + 7) #define inf 1e9 + 1e9 using namespace std; typedef long double ld; typedef long long ll; typedef short int si; int a[N], an, L = 1, R = 1, ans[N], pos[N]; bool cmp(int x, int y) {return abs(pos[x] - x) > abs(pos[y] - y);} int main() { // freopen("input4.txt", "r", stdin); freopen("output4.txt", "w", stdout); ios_base::sync_with_stdio(0); istream::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; vector <int> gn; gn.clear(); for (int i = 1; i <= n; i++) {gn.pb(i); cin >> a[i]; pos[a[i]] = i; ans[i] = -1;} sort(gn.begin(), gn.end(), cmp); for (auto it : gn) { if (ans[it] != -1) { if (ans[it] > an) { an = ans[it]; L = it; R = pos[it]; if (L > R) swap(L, R); } continue; } int l = it, r = pos[it]; if (l > r) swap(l, r); if (l == r || r - l <= an) continue; int curl, curr, kol = 0; if ((r - l) % 2) {curl = (r + l) / 2; curr = curl + 1;} else {curl = ((r + l) / 2) - 1; curr = curl + 2;} while (l <= curl && curr <= r) { if (a[curl] == curl) kol--; if (a[curr] == curr) kol--; if (a[curr] == curl) kol++; if (a[curl] == curr) kol++; if (a[curr] == curl) ans[curl] = kol; if (a[curl] == curr) ans[curr] = kol; curl--; curr++; } if (kol > an) { an = kol; L = l; R = r; } } cout << a[L] << " " << a[R] << endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...