이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define F first
#define S second
#define FOR(i,a,b) for (auto i = (a); i <= (b); ++i)
#define NFOR(i,a,b) for(auto i = (a); i >= (b); --i)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define mp(i,a) make_pair(i,a)
#define pb(a) push_back(a)
#define bit(x,b) (x&(1LL<<b))
typedef int lli;
typedef pair <lli,lli> ii;
typedef pair <lli,ii> iii;
typedef vector <lli> vi;
typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
int n,c,r;
int segt[400001],segt1[400001],lazy[400001];
void up(int node,int l,int r,int in,int v)
{
if(l==r)
{
segt[node]=v;
return;
}
int m=(l+r)/2;
if(in<=m)
up(2*node+1,l,m,in,v);
else
up(2*node+2,m+1,r,in,v);
segt[node]=max(segt[2*node+1],segt[2*node+2]);
}
int qu(int node,int l,int r,int s,int e)
{
if(l>e||r<s)
return(0);
if(l>=s&&r<=e)
return segt[node];
int m=(l+r)/2;
int q1=qu(2*node+1,l,m,s,e),q2=qu(2*node+2,m+1,r,s,e);
return max(q1,q2);
}
void up1(int node,int l,int r,int s,int e)
{
if(l>e||r<s)
return;
if(lazy[node]!=0)
{
segt1[node]+=lazy[node];
if(l!=r)
{
lazy[2*node+1]+=lazy[node];
lazy[2*node+2]+=lazy[node];
}
lazy[node]=0;
}
if(l>=s&&r<=e)
{
segt1[node]+=1;
if(l!=r)
{
lazy[2*node+1]+=1;
lazy[2*node+2]+=1;
}
return;
}
int m=(l+r)/2;
up1(2*node+1,l,m,s,e);
up1(2*node+2,m+1,r,s,e);
segt1[node]=max(segt1[2*node+1],segt1[2*node+2]);
}
int qu1(int node,int l,int r,int s,int e)
{
if(l>e||r<s)
return(0);
if(lazy[node]!=0)
{
segt1[node]+=lazy[node];
if(l!=r)
{
lazy[2*node+1]+=lazy[node];
lazy[2*node+2]+=lazy[node];
}
lazy[node]=0;
}
if(l>=s&&r<=e)
return segt1[node];
int m=(l+r)/2;
int q1=qu1(2*node+1,l,m,s,e),q2=qu1(2*node+2,m+1,r,s,e);
return max(q1,q2);
}
ordered_set s;
vector<ii> v;
int GetBestPosition(int N, int C, int R, int *K, int *S, int *E)
{
n=N;
c=C;
r=R;
for(int i=0;i<n-1;++i)
up(0,0,n-2,i,K[i]);
for(int i=0;i<n;++i)
s.insert(mp(i,i));
for(int i=0;i<c;++i)
{
int f=S[i],sec=E[i],co=0,fi,se;
while(co<(sec-f))
{
if(co==0)
fi=(*s.find_by_order(f)).S;
s.erase((*s.find_by_order(f)));
co++;
}
se=(*s.find_by_order(f)).F;
s.erase((*s.find_by_order(f)));
v.pb(mp(fi,se));
s.insert(mp(se,fi));
}
for(int i=0;i<c;++i)
{
if(qu(0,0,n-2,v[i].F,v[i].S-1)<r)
up1(0,0,n-1,v[i].F,v[i].S);
}
int m=0,in=0,cur;
for(int i=0;i<n;++i)
{
cur=qu1(0,0,n-1,i,i);
if(cur>m)
{
m=cur;
in=i;
}
}
return in;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |