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>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
int n ;
int bit[100001];
void add(int e,int v){
e++;
while(e<=1e5){
bit[e]+=v;
e+=e&-e;
}
}
long long sum(int e){
e++;
long long res = 0;
while(e>=1){
res+=bit[e];
e -= e&-e;
}
return res;
}
int GetBestPosition(int N, int C, int R, int *K, int *S, int *E){
set<int> bst;
for(int i = 0;i<N-1;i++){
if(K[i]>R){
bst.insert(i);
}
}
ordered_set s;
for(int i = 0;i<=N;i++){
s.insert(i);
}
int ans[N] = {0};
set<int> rem;
for(int i = 0;i<N;i++)rem.insert(i);
for(int i = 0;i<C;i++){
int l = *s.find_by_order(S[i]) , r = (*s.find_by_order(E[i]+1))-1;
if(l==r)continue;
while(*s.lower_bound(l)<=r){
s.erase(s.lower_bound(l));
}
auto it = bst.lower_bound(l);
if(it!=bst.end()&&*it<=r-1){
auto it2 = rem.lower_bound(l);
while(it2!=rem.end()&&*it2<=r){
ans[(*it2)] = sum((*it2));
rem.erase(it2);
it2 = rem.lower_bound(l);
}
}else{
add(l,1);
add(r+1,-1);
}
}
for(auto i:rem){
ans[i] = sum(i);
}
int lol = -1 , ind = 0;
for(int i = 0;i<n;i++){
if(lol<ans[i]){
lol = ans[i];
ind = i;
}
}
return ind;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |