QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#619178#2442. Welcome PartyAnotherDayofSun#AC ✓287ms10728kbC++201.0kb2024-10-07 13:26:112024-10-07 13:26:12

Judging History

This is the latest submission verdict.

  • [2024-10-07 13:26:12]
  • Judged
  • Verdict: AC
  • Time: 287ms
  • Memory: 10728kb
  • [2024-10-07 13:26:11]
  • Submitted

answer

#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=1e5+3;
int t,n,b[N],ans;
struct gg{
    int x,y;
}a[N];
set<int>s;
set<int>::iterator it;
bool cmp(gg a,gg b){
    if(a.x==b.x)return a.y<b.y;
    return a.x>b.x;
}
signed main(){
    b[0]=a[0].y=-3e18;
    scanf("%lld",&t);
    while(t--){
        scanf("%lld",&n);
        for(int i=1;i<=n;++i){
            scanf("%lld %lld",&a[i].x,&a[i].y);
        }
        sort(a+1,a+n+1,cmp);
        for(int i=1;i<=n;++i){
            b[i]=max(b[i-1],a[i-1].y);
        }
        s.clear();
        s.insert(-3e18);
        s.insert(3e18);
        ans=6e18;
        for(int i=n;i;--i){
            it=s.lower_bound(a[i].x);
            --it;
            if(abs(b[i]-a[i].x)>abs(*it-a[i].x)&&(*it)>b[i])b[i]=*it;
            ++it;
            if(abs(b[i]-a[i].x)>abs(*it-a[i].x)&&(*it)>b[i])b[i]=*it;
            ans=min(ans,abs(b[i]-a[i].x));
            s.insert(a[i].y);
        }
        cout<<ans<<endl;
    }
}

详细

Test #1:

score: 100
Accepted
time: 287ms
memory: 10728kb

input:

66
5
27 46
89 13
55 8
71 86
22 35
3
3 5
4 7
6 2
2
0 1000000000
1000000000 0
2
1000000000 0
0 1000000000
2
1000000000 0
1000000000 0
2
0 1000000000
0 1000000000
2
1000000000 1000000000
0 0
2
0 0
0 0
2
1000000000 1000000000
1000000000 1000000000
3
90 30
90 50
90 85
3
0 0
0 2
0 5
3
20 30
20 50
20 70
3
...

output:

3
1
0
0
1000000000
1000000000
1000000000
0
0
5
0
10
5
10
3
0
10
5
0
5
0
10
5
10
3
0
10
5
0
146595730144168239
10974087366700578
21076180420813408
183538167814754058
46751451188711820
365292306661444331
23639646046527434
40476687889457528
270663364266559542
139940820548070767
21494649603533736
100200...

result:

ok 66 lines