QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#370984 | #4906. 球球 | zsq147258369 | 5 | 2ms | 3752kb | C++17 | 3.3kb | 2024-03-29 20:37:26 | 2024-03-29 20:37:26 |
answer
#include<bits/stdc++.h>
using namespace std;
const int N=2e6+500,inf=2e9;
int n,t[N],x[N];
struct node
{
int l,r;
friend bool operator<(node a,node b)
{
return a.l<b.l;
}
friend bool operator<(node a,int b)
{
return a.l<b;
}
int dis(const int x,const int d) const
{
int ll=l-d,rr=r+d;
if(ll<=x&&rr>=x)return 0;
return min(abs(ll-x),abs(rr-x));
}
};
struct Set
{
int d;set<node>s;
void insert(int l,int r)
{
l+=d,r-=d;
auto it=lower_bound(s.begin(),s.end(),l);
if(it!=s.begin())
{
it--;
if((*it).r>=r)return;
it++;
}
if(it==s.end())
{
s.insert((node){l,r});
return;
}
if((*it).l<=l&&(*it).r>=r)return;
// cout<<"int "<<l<<' '<<r<<'\n';
// for(auto x:s)cout<<x.l<<' '<<x.r<<'\n';
// if(it!=s.begin())--it,cout<<"IT "<<(*it).l<<' '<<(*it).r<<'\n',++it;
// else puts("is begin");
// puts("");
auto bg=it;
while(it!=s.end()&&(*it).r<=r)++it;
s.erase(bg,it);s.insert((node){l,r});
}
void clear()
{
s.clear();d=0;
}
int dis(int x)
{
if(s.empty())return inf;
auto it=lower_bound(s.begin(),s.end(),x);
if(it==s.end())return (*--it).dis(x,d);
if(it==s.begin())return (*it).dis(x,d);
return min((*it).dis(x,d),(*--it).dis(x,d));
}
int find(int l,int r,int&mi,int&mx)
{
mi=inf,mx=-inf;
auto it=lower_bound(s.begin(),s.end(),l);
if(it!=s.end())mi=max(l,(*it).l-d);if(it!=s.begin())it--,mi=((*it).r+d>=l?l:mi);
it=lower_bound(s.begin(),s.end(),r);
if(it!=s.end())mx=((*it).l-d<=r?r:-inf);if(it!=s.begin())it--,mx=max(mx,min(r,(*it).r+d));
if(mi>r)mi=inf;if(mx<l)mx=-inf;
return mi!=inf;
}
void put()
{
for(auto x:s)
{
cout<<d<<' '<<x.l-d<<' '<<x.r+d<<'\n';
}
}
}S,T;
main()
{
// freopen("in.txt","r",stdin);
// freopen("out.txt","w",stdout);
cin>>n;
for(int i=1;i<=n;i++)cin>>t[i]>>x[i];
S.insert(0,0),T.insert(0,0);
for(int i=1;i<=n;i++)
{
if(S.s.empty()&&T.s.empty())
{
puts("NO");
return 0;
}
int u=x[i-1],v=x[i],dt=t[i]-t[i-1];
int d1=S.dis(v),d2=T.dis(v),d3=min(d1,T.s.empty()?inf:abs(u-v)),mi,mx;S.find(v-dt,v+dt,mi,mx);
// cout<<"solve "<<d1<<' '<<d2<<' '<<d3<<' '<<mi<<' '<<mx<<' '<<v-dt<<' '<<v+dt<<'\n';
if(!T.s.empty()&&u>=v-dt&&u<=v+dt)mi=min(mi,u),mx=max(mx,u);
if(u==v)S.d+=dt;else S.clear();if(abs(u-v)>dt)T.clear();
if(d2==0)S.insert(u-dt,u+dt);if(d1<=dt)T.insert(u,u);
if(d3<=dt)S.insert(v-dt+d3,v+dt-d3);
if(mi!=inf)
{
int w=(dt-abs(v-mi))/2;
T.insert(min(mi,v)-w,max(mi,v)+w);
}
if(mx!=-inf)
{
int w=(dt-abs(v-mx))/2;
T.insert(min(mx,v)-w,max(mx,v)+w);
}
// cout<<i<<'\n';
// cout<<"S:\n";
// S.put();
// cout<<"T:\n";
// T.put();
}
if(!S.s.empty()||!T.s.empty())puts("YES");
else puts("NO");
}
詳細信息
Subtask #1:
score: 5
Accepted
Test #1:
score: 5
Accepted
time: 0ms
memory: 3496kb
input:
5 2 1 3 2 9 6 10 5 13 -1
output:
NO
result:
ok single line: 'NO'
Test #2:
score: 0
Accepted
time: 1ms
memory: 3700kb
input:
5 1 1 3 2 4 -1 6 4 10 -1
output:
NO
result:
ok single line: 'NO'
Test #3:
score: 0
Accepted
time: 1ms
memory: 3608kb
input:
4 16 13 18 4 20 3 21 5
output:
NO
result:
ok single line: 'NO'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3524kb
input:
5 2 1 3 2 8 6 10 5 13 0
output:
YES
result:
ok single line: 'YES'
Test #5:
score: 0
Accepted
time: 1ms
memory: 3712kb
input:
5 2 1 3 2 9 6 10 5 13 0
output:
YES
result:
ok single line: 'YES'
Test #6:
score: 0
Accepted
time: 0ms
memory: 3672kb
input:
5 1 1 3 2 4 0 6 4 10 -1
output:
YES
result:
ok single line: 'YES'
Test #7:
score: 0
Accepted
time: 0ms
memory: 3716kb
input:
3 1 0 5 5 6 2
output:
YES
result:
ok single line: 'YES'
Test #8:
score: 0
Accepted
time: 0ms
memory: 3548kb
input:
5 2 1 6 0 7 -1 8 2 9 -2
output:
YES
result:
ok single line: 'YES'
Test #9:
score: 0
Accepted
time: 0ms
memory: 3668kb
input:
5 30 10 40 -10 51 9 52 8 53 20
output:
YES
result:
ok single line: 'YES'
Test #10:
score: 0
Accepted
time: 0ms
memory: 3612kb
input:
3 2 2 5 5 6 1
output:
YES
result:
ok single line: 'YES'
Subtask #2:
score: 0
Wrong Answer
Dependency #1:
100%
Accepted
Test #11:
score: 0
Wrong Answer
time: 1ms
memory: 3700kb
input:
100 51823 -51823 80072 -23574 152202 48556 263343 -14629 356859 -38607 441850 -193136 442857 -192129 471412 -108145 504392 -187704 582081 -265393 680615 -220684 775219 -261463 781624 -267868 801370 -287614 899570 -166859 982377 -272221 1048767 -338611 1094930 -189414 1170308 -460152 1222829 -512673 ...
output:
NO
result:
wrong answer 1st lines differ - expected: 'YES', found: 'NO'
Subtask #3:
score: 0
Skipped
Dependency #2:
0%
Subtask #4:
score: 0
Wrong Answer
Test #91:
score: 0
Wrong Answer
time: 2ms
memory: 3752kb
input:
5000 6 6 80 80 170 48 240 106 243 179 329 176 412 93 485 176 552 249 555 316 613 371 650 313 733 251 735 253 736 334 815 254 893 333 943 255 965 227 1022 284 1116 205 1174 320 1230 376 1318 378 1336 288 1430 212 1494 276 1562 344 1597 309 1638 350 1716 272 1793 349 1809 365 1908 306 1951 464 2037 42...
output:
NO
result:
wrong answer 1st lines differ - expected: 'YES', found: 'NO'
Subtask #5:
score: 0
Skipped
Dependency #3:
0%
Subtask #6:
score: 0
Skipped
Dependency #5:
0%
Subtask #7:
score: 0
Skipped
Dependency #4:
0%
Subtask #8:
score: 0
Skipped
Dependency #7:
0%