# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1094293 | alexdd | Santa Claus (RMI19_santa) | C++17 | 322 ms | 13392 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 <bits/stdc++.h>
using namespace std;
int n;
pair<int,int> aint[270000];
pair<int,int> emp = {0,0};
pair<int,int> combine(pair<int,int> x, pair<int,int> y)
{
return {x.first + y.first, min(x.second, x.first + y.second)};
}
void upd(int nod, int st, int dr, int poz, int newv)
{
if(st==dr)
{
aint[nod].first += newv;
aint[nod].second += newv;
return;
}
int mij=(st+dr)/2;
if(poz<=mij) upd(nod*2,st,mij,poz,newv);
else upd(nod*2+1,mij+1,dr,poz,newv);
aint[nod] = combine(aint[nod*2], aint[nod*2+1]);
}
int x[100000],h[100000],v[100000];
int rez[100000];
signed main()
{
int t;
cin>>t;
while(t--)
{
cin>>n;
for(int i=0;i<min(4*n+2,270000);i++)
aint[i] = emp;
int ult0=0;
for(int i=1;i<=n;i++)
cin>>x[i];
for(int i=1;i<=n;i++)
{
cin>>h[i];
if(h[i]==0) ult0=i;
rez[i] = -1;
}
for(int i=1;i<=n;i++)
cin>>v[i];
set<pair<int,int>> s;
for(int i=1;i<=ult0;i++)
{
if(h[i]==0) upd(1,1,n,v[i],-1);
else upd(1,1,n,v[i],+1);
}
int st=1;
for(int dr=ult0;dr<=n;dr++)
{
if(dr>ult0)
{
assert(h[dr]==1);
upd(1,1,n,v[dr],+1);
}
while(st<=dr && aint[1].second>=0)
{
if(h[st]==0)
{
s.insert({v[st],st});
}
else
{
upd(1,1,n,v[st],-1);
auto it = s.lower_bound({v[st],-1});
if(it!=s.end())
{
upd(1,1,n,(*it).first,+1);
s.erase(it);
}
}
st++;
}
if(st==1)
rez[dr] = -1;
else
rez[dr] = 2*x[dr] - x[st-1];
}
for(int i=1;i<=n;i++)
cout<<rez[i]<<" ";
cout<<"\n";
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |