题解:AT_arc174_f [ARC174F] Final Stage
朴素的 dp 是简单的,设
我们考虑直接维护
考虑维护
发现每次其实会给输的段的
用差分描述:把第奇数个
考虑维护这些
注意到有些平移后输的段可能满足
使用两个堆
每次取出
我们还需要动态支持删除一些
时间复杂度
#include<bits/stdc++.h>
#define ll long long
#define pir pair<ll,ll>
#define mkp make_pair
#define fi first
#define se second
#define pb push_back
using namespace std;
const ll maxn=1e6+10;
ll n,m,l[maxn],r[maxn],pre[maxn],nxt[maxn],vis[maxn],pos[maxn],tag0,tag1,tot=2,hd,x[maxn],len,g;
set<pir>st0,st1;
int main(){
// freopen("p.in","r",stdin);
scanf("%lld",&n);
for(ll i=1;i<=n;i++){
scanf("%lld%lld",l+i,r+i);
}
pre[2]=1, nxt[1]=2;
pos[1]=0, pos[2]=l[n];
hd=1; g=0;
st0.insert(mkp(l[n],1));
for(ll i=n-1;i;i--){
if(g==0){
tag0+=l[i], tag1+=r[i];
while(!st1.empty()&&st1.begin()->fi+tag0-tag1<=0){
pir t=*st1.begin(); st1.erase(st1.begin());
ll x=t.se, y=nxt[x];
if(!nxt[y]){
nxt[x]=0;
continue;
}
if(!pre[x]) hd=nxt[y];
nxt[pre[x]]=nxt[y], pre[nxt[y]]=pre[x];
if(pre[x]) st0.erase(mkp(pos[x]-pos[pre[x]],pre[x]));
if(nxt[y]) st0.erase(mkp(pos[nxt[y]]-pos[y],y));
if(pre[x]&&nxt[y]) st0.insert(mkp(pos[nxt[y]]-pos[pre[x]],pre[x]));
}
++tot, pos[tot]=-tag1;
g^=1;
nxt[tot]=hd, pre[hd]=tot;
st1.insert(mkp(pos[hd]-pos[tot],tot)), hd=tot;
}
else{
tag1+=l[i], tag0+=r[i];
while(!st0.empty()&&st0.begin()->fi+tag1-tag0<=0){
pir t=*st0.begin(); st0.erase(st0.begin());
ll x=t.se, y=nxt[x];
if(!nxt[y]){
nxt[x]=0;
continue;
}
if(!pre[x]) hd=nxt[y];
nxt[pre[x]]=nxt[y], pre[nxt[y]]=pre[x];
if(pre[x]) st1.erase(mkp(pos[x]-pos[pre[x]],pre[x]));
if(nxt[y]) st1.erase(mkp(pos[nxt[y]]-pos[y],y));
if(pre[x]&&nxt[y]) st1.insert(mkp(pos[nxt[y]]-pos[pre[x]],pre[x]));
}
++tot, pos[tot]=-tag0;
g^=1;
nxt[tot]=hd, pre[hd]=tot;
st0.insert(mkp(pos[hd]-pos[tot],tot)), hd=tot;
}
}
ll u=hd;
while(u){
x[++len]=pos[u]+(g&1? tag1:tag0); g^=1;
u=nxt[u];
}
scanf("%lld",&m);
while(m--){
ll c; scanf("%lld",&c);
ll tmp=upper_bound(x+1,x+1+len,c)-x-1;
if(tmp==len) puts("Draw");
else puts((tmp^1)&1? "Alice":"Bob");
}
return 0;
}