QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#370950#4906. 球球zsq1472583690 2ms3700kbC++173.2kb2024-03-29 20:02:252024-03-29 20:02:44

Judging History

你现在查看的是最新测评结果

  • [2024-03-29 20:02:44]
  • 评测
  • 测评结果:0
  • 用时:2ms
  • 内存:3700kb
  • [2024-03-29 20:02:25]
  • 提交

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);
        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<<' '<<x.r<<'\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);
        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: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3540kb

input:

5
2 1
3 2
9 6
10 5
13 -1

output:

YES

result:

wrong answer 1st lines differ - expected: 'NO', found: 'YES'

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Skipped

Dependency #2:

0%

Subtask #4:

score: 0
Wrong Answer

Test #91:

score: 0
Wrong Answer
time: 2ms
memory: 3700kb

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%