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>
#pragma GCC optimize ("Ofast")
#pragma GCC target ("avx2")
using namespace std;
using ll = long long;
using ii = pair<ll, ll>;
#define ff first
#define ss second
#define pb push_back
/// #define int ll
const int MOD = 1e9 + 7;
int par[100001], mx[100001];
int findSet(int v) {
if(par[v] == v) return v;
return par[v] = findSet(par[v]);
}
int GetBestPosition(int N, int C, int R, int *K, int *S, int *E) {
int res = 0, curr = 0;
vector<ii> query; vector<int> s;
for(int l = 0; l < N; l++) s.push_back(l);
for(int l = 0; l < C; l++) {
int lf = S[l], rf = E[l]; query.pb({s[lf], s[rf]});
s.erase(s.begin() + lf + 1, s.begin() + rf + 1);
}
for(int l = 0; l < N; l++) {
for(int i = 0; i < l; i++)
par[i] = i, mx[i] = K[i];
par[l] = l; mx[l] = R;
for(int i = l; i < N - 1; i++)
par[i + 1] = i + 1, mx[i + 1] = K[i];
int calc = 0;
for(auto u : query) {
int lf = u.ff, rf = u.ss;
lf = findSet(lf), rf = findSet(rf);
if(lf > rf) swap(lf, rf);
par[rf] = lf; mx[lf] = max(mx[lf], mx[rf]);
if(mx[lf] == R) calc++;
}
if(calc > curr) {
curr = calc, res = l;
}
}
return res;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |