#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define fi first
#define sc second
typedef pair<int,int> pii;
typedef tree< pii, null_type, less<pii>, rb_tree_tag,
tree_order_statistics_node_update> ordered_set;
const int MAXN = 1e5+5;
int v[MAXN];
int GetBestPosition(int n, int c, int r, int *K, int *s, int *e) {
v[0] = r;
for(int i = 0; i < n; i++)v[i+1] = K[i];
int ans = 0;
for(int i = 0; i < n; i++){
if(i != 0)swap(v[i-1],v[i]);
ordered_set st;
for(int j = 0; j < n; j++)st.insert({j,v[j]});
int cur = 0;
for(int j = 0; j < c; j++){
int x = e[j]-s[j], mx = 0, l;
for(int k = 0; k <= x; k++){
auto it = st.find_by_order(s[j]);
if(k == 0)l = it->fi;
mx = max(mx,it->sc);
st.erase(it);
}
if(mx == r)cur++;
st.insert({l, mx});
}
ans = max(ans,cur);
}
return ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |