QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#875708 | #7335. Evacuation | woshiSB_river | RE | 0ms | 0kb | C++14 | 5.0kb | 2025-01-30 10:16:07 | 2025-01-30 10:16:08 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
inline int read()
{ int x=0;
bool f=0;
char c=getchar();
while(!isdigit(c))f|=(c=='-'),c=getchar();
while(isdigit(c))x=x*10+(c&15),c=getchar();
return f?-x:x;
}
using namespace std;
struct ques
{ int opt,t,l,r,id;
}op[400005];
struct bb
{ int t,l,r;
bool operator <(const bb &b)const{return l==b.l?r<b.r:l<b.l;}
}tp,dl[10];
struct BB
{ int t;
bb l,r;
bool operator <(const BB &b)const{return t<b.t;}
};
int T,n,q,now,cnt;
bool ans[200005];
set<bb> s;
set<bb>::iterator L,R;
set<BB> S;
set<BB>::iterator ls;
inline bool cmp(const ques &a,const ques &b){return a.t==b.t?a.opt<b.opt:a.t<b.t;}
inline void check(const bb &a,const bb &b){int t=(b.l+b.t-a.r+a.t)/2;S.insert({t,a,b});return ;}
inline bool eras(const bb &a,int l,int r)
{ int L=a.l-(now-a.t),R=a.r+(now-a.t);
if(l<=L&&R<=r)
{ s.erase(a);
return 1;
}
if(L<=l&&r<=R)
{ s.erase(a);
dl[++cnt].t=now,dl[cnt].l=L,dl[cnt].r=l-1;
if(dl[cnt].l>dl[cnt].r)cnt--;
dl[++cnt].t=now,dl[cnt].l=r+1,dl[cnt].r=R;
if(dl[cnt].l>dl[cnt].r)cnt--;
return 1;
}
if(L>=l&&L<=r)
{ s.erase(a);
dl[++cnt].t=now,dl[cnt].l=r+1,dl[cnt].r=R;
if(dl[cnt].l>dl[cnt].r)cnt--;
return 1;
}
if(R>=l&&R<=r)
{ s.erase(a);
dl[++cnt].t=now,dl[cnt].l=L,dl[cnt].r=l-1;
if(dl[cnt].l>dl[cnt].r)cnt--;
return 1;
}
return 0;
}
signed main()
{ freopen("ls.in","r",stdin);
freopen("ls.out","w",stdout);
T=read();
while(T--)
{ n=read();
for(int i=1,x,r;i<=n;++i)
{ op[i].opt=0,op[i].t=read();
x=read(),r=read();
op[i].l=x-r+1,op[i].r=x+r-1;
}
q=read();
for(int i=1;i<=q;++i)op[i+n].opt=1,op[i+n].t=read(),op[i+n].l=op[i+n].r=read(),op[i+n].id=i,ans[i]=0;
sort(op+1,op+n+q+1,cmp);
s.clear(),S.clear(),now=0;
s.insert({0,0,0});
for(int i=1;i<=n+q;++i)
{ //cerr<<op[i].opt<<' '<<op[i].t<<' '<<op[i].l<<' '<<op[i].r<<endl;
//for(auto TP:s)cerr<<TP.t<<' '<<TP.l<<' '<<TP.r<<endl;
now=op[i].t;
if(!S.empty())ls=S.begin();
while(!S.empty()&&(*ls).t<=now)
{ //cerr<<"???"<<(*ls).t<<' '<<(*ls).l.l<<' '<<(*ls).l.r<<" "<<(*ls).r.l<<' '<<(*ls).r.r<<endl;
L=s.find((*ls).l),R=s.find((*ls).r);
if(L!=s.end()&&R!=s.end())
{ int tl=(*L).l-(now-(*L).t),tr=(*R).r+(now-(*R).t);
tp.t=now,tp.l=tl,tp.r=tr;
if(L!=s.begin())
{ L--;
check(*L,tp);
L++;
}
R++;
if(R!=s.end())check(tp,*R);
R--;
s.insert(tp);
s.erase(L),s.erase(R);
}
S.erase(ls);
if(!S.empty())ls=S.begin();
}
if(op[i].opt==0)
{ cnt=0;
L=s.lower_bound({0,op[i].l,op[i].l});
if(L!=s.begin())L--;
bool flag=0;
for(;L!=s.end();)
{ R=L;
R++;
if(eras(*L,op[i].l,op[i].r))flag=1;
else if(flag)break;
L=R;
}
//cerr<<"#!#$@ "<<cnt<<endl;
for(int j=1;j<=cnt;++j)s.insert(dl[j]);//,cerr<<dl[j].l<<' '<<dl[j].r<<endl;
for(int j=1;j<=cnt;++j)
{ L=s.find(dl[j]);
if(L!=s.begin())
{ L--;
check(*L,dl[j]);
L++;
}
if(j==cnt)
{ L++;
if(L!=s.end())check(dl[j],*L);
}
}
}
else
{ L=s.lower_bound({0,op[i].l,op[i].r});
if(L==s.end())
{ L--;
if((*L).r+(now-(*L).t)>=op[i].r)ans[op[i].id]|=1;
}
else if(L!=s.begin())
{ L--;
if((*L).r+(now-(*L).t)>=op[i].r)ans[op[i].id]|=1;
L++;
if((*L).l-(now-(*L).t)<=op[i].l)ans[op[i].id]|=1;
}
else if((*L).l-(now-(*L).t)<=op[i].l)ans[op[i].id]|=1;
}
}
if(T==1102)
{ cout<<n<<endl;
for(int i=1;i<=n;++i)cout<<op[i].t<<' '<<(op[i].l+op[i].r)/2<<' '<<op[i].r-(op[i].l+op[i].r)/2+1<<endl;
cout<<q<<endl;
for(int i=1;i<=q;++i)cout<<op[i+n].t<<' '<<op[i+n].l<<endl;
}
for(int i=1;i<=q;++i)
{ if(ans[i])printf("@");
else printf("*");
}
printf("\n");
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Dangerous Syscalls
input:
1 2 3 -1 1 2 1 1 3 1 1 3 1 2 1