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>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define fi first
#define se second
using namespace std;
using namespace __gnu_pbds;
const int NN=1e5;
const int L=17;
int d[NN+10];
tree<pair<int,int>,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update> st;
int mx[L+2][2][NN+10];
void build_rmq(int N,int *K)
{
for(int rot:{1,0})
{
for(int i=0;i<N-1;i++)
{
mx[0][rot][i]=K[i];
for(int j=1;j<=L;j++)
{
if(i-(1<<(j-1))<0)
mx[j][rot][i]=mx[j-1][rot][i];
else
mx[j][rot][i]=max(mx[j-1][rot][i],mx[j-1][rot][i-(1<<(j-1))]);
}
}
reverse(K,K+N-1);
for(int j=0;j<=L;j++)
{
reverse(mx[j][0],mx[j][0]+N-1);
reverse(mx[j][1],mx[j][1]+N-1);
}
}
return;
}
int get_max(int l,int r)
{
int lg=__lg(r-l+1);
return max(mx[lg][0][l],mx[lg][1][r]);
}
void add_interval(int l,int r,int R)
{
if(l==r || get_max(l,r-1)<R)
{
d[l]++;
d[r+1]--;
}
return;
}
int GetBestPosition(int N,int C,int R,int *K,int *S,int *E)
{
build_rmq(N,K);
for(int i=0;i<N;i++)
st.insert(make_pair(i,i));
for(int i=0;i<C;i++)
{
auto s=(*st.find_by_order(S[i])),e=(*st.find_by_order(E[i]));
add_interval(s.fi,e.se,R);
st.erase(s);
st.insert(make_pair(s.fi,e.se));
for(int j=E[i];j>S[i];j--)
st.erase(st.find_by_order(j));
}
int ans=0,bst=0;
int curr=0;
for(int i=0;i<N;i++)
{
curr+=d[i];
if(curr>ans)
{
ans=curr;
bst=i;
}
}
return bst;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |