#include "meetings.h"
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
typedef long long ll;
using namespace std;
ll n,i,a[101010],ST[404040],ki[101010],ka[101010];
void upd(ll aa,ll bb,ll cc,ll dd,ll ee)
{
if(aa==bb)ST[ee]=dd;
else
{
ll ce=(aa+bb)/2;
if(cc<=ce)upd(aa,ce,cc,dd,ee*2);
else upd(ce+1,bb,cc,dd,ee*2+1);
ST[ee]=max(ST[ee*2],ST[ee*2+1]);
}
}
ll que(ll aa,ll bb,ll cc,ll dd,ll ee)
{
if(bb<cc||dd<aa)return 0;
else
if(cc<=aa&&bb<=dd)return ST[ee];
else
{
ll ce=(aa+bb)/2;
return max(que(aa,ce,cc,dd,ee*2),que(ce+1,bb,cc,dd,ee*2+1));
}
}
std::vector<long long> minimum_costs(std::vector<int> H, std::vector<int> L,std::vector<int> R)
{
n=H.size();
for(i=1;i<=n;i++)a[i]=H[i-1];
for(i=1;i<=n;i++)
if(a[i]==a[i-1])
ki[i]=ki[i-1];
else
ki[i]=i;
for(i=n;i>=1;i--)
if(a[i]==a[i+1])
ka[i]=ka[i+1];
else
ka[i]=i;
//for(i=1;i<=n;i++)cout<<i<<" "<<ki[i]<<" "<<ka[i]<<"\n";
for(i=1;i<=n;i++)
if(a[i]==1)
upd(1,n,i,ka[i]-ki[i]+1,1);
int Q = L.size();
std::vector<long long> C(Q);
for (int j = 0; j < Q; ++j)
{
L[j]++;
R[j]++;
//cout<<ka[L[j]]<<" "<<ki[R[j]]<<"\n";
C[j]=que(1,n,ka[L[j]]+1,ki[R[j]]-1,1);
//cout<<C[j]<<"_\n";
if(a[R[j]]==1&&ki[R[j]]>=L[j])C[j]=max(C[j],R[j]-ki[R[j]]+1);
if(a[L[j]]==1&&ka[L[j]]<=R[j])C[j]=max(C[j],ka[L[j]]-L[j]+1);
C[j]=2*(R[j]-L[j]+1)-C[j];
}
return C;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
348 KB |
Output is correct |
2 |
Incorrect |
39 ms |
1932 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
348 KB |
Output is correct |
2 |
Incorrect |
39 ms |
1932 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |