# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
412881 | Ahmadsm2005 | Meetings (IOI18_meetings) | C++14 | 0 ms | 0 KiB |
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 "meetings.h"
#include "grader.cpp"
#include<bits/stdc++.h>
using namespace std;
int sparse[750001][21],LOG[750001];
int query(int L,int R){
if(L>R)
return 0;
int Q=LOG[R-L+1];
return max(sparse[L][Q],sparse[R-(1<<Q)+1][Q]);
}
int BS(int L,int R){
int LL=L,RR=R,CUR=query(L,L),mid,LAST=LL;
while(LL<=RR){
mid=(LL+RR)/2;
if((mid-L)+CUR==query(L,mid))
LAST=max(LAST,mid),LL=mid+1;
else
RR=mid-1;
}
return max(query(L,LAST)-max(CUR-1,0),query(LAST+1,R));
}
vector<long long>minimum_costs(vector<int>H,vector<int>L,vector<int>R){
vector<long long>ANS;
LOG[1]=0;
for(int i=2;i<=750000;i++)
LOG[i]=LOG[i/2];
sparse[0][0]=((H[0]==1)?1:0);
for(int i=1;i<H.size();i++)
sparse[i][0]=((H[i]==1)?sparse[i-1][0]+1:0);
for(int l=1;l<21;l++){
for(int i=0;i+(1<<(l-1))<H.size();i++){
sparse[i][l]=max(sparse[i][l-1],sparse[i+(1<<(l-1))][l-1]);
}
}
for(int i=0;i<L.size();i++)
ANS.push_back((R[i]-L[i]+1)*2-BS(L[i],R[i]));
return ANS;
}