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 ll long long
#define ld long double
#define sp ' '
#define en '\n'
#define smin(a, b) a = min(a, b)
#define smax(a, b) a = max(a, b)
using namespace std;
const int N = 1e5 + 2;
const int inf = 1e9;
int l[N], r[N], ans[N], gde[N];
vector<int> b;
bool Has(int x, int y) {
auto it = lower_bound(b.begin(), b.end(), x);
if (it == b.end()) return false;
return *it < y;
}
int GetBestPosition(int n, int q, int k, int *p, int *s, int *e) {
for (int i = 0; i < n - 1; i++) if (p[i] > k) b.push_back(i);
for (int i = 0; i < n; i++) l[i] = r[i] = gde[i] = i;
for (int i = 0; i < q; i++) {
int idx = gde[s[i]]; int idy = gde[e[i]];
r[idx] = r[idy];
for (int j = s[i] + 1; j <= n - 1 - e[i] + s[i]; j++) gde[j] = gde[j + e[i] - s[i]];
if (!Has(l[idx], r[idx])) {
ans[l[idx]]++;
ans[r[idx] + 1]--;
}
}
int pos = 0;
for (int i = 0; i < n; i++) {
if (i > 0) ans[i] += ans[i - 1];
if (ans[i] > ans[pos]) pos = i;
}
return pos;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |