QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#619381#2442. Welcome PartyWorldFinalEscaped#AC ✓267ms10824kbC++141.3kb2024-10-07 14:02:582024-10-07 14:03:03

Judging History

This is the latest submission verdict.

  • [2024-10-07 14:03:03]
  • Judged
  • Verdict: AC
  • Time: 267ms
  • Memory: 10824kb
  • [2024-10-07 14:02:58]
  • Submitted

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+5;
#define F first
#define S second
pair<ll,ll> a[N];
ll suf[N];
int T,n;
set<ll> s;
bool cmp(pair<ll,ll> a, pair<ll,ll> b){
    return a.F<b.F || (a.F==b.F && a.S>b.S);
}
int main(){
    // freopen("a.in","r",stdin);
    // freopen("a.out","w",stdout);
    for (cin>>T; T; T--){
        scanf("%d",&n);
        for (int i=1; i<=n; i++) scanf("%lld%lld",&a[i].F,&a[i].S);
        sort(a+1,a+1+n,cmp); ll ans=2e18;
        for (int i=n; i>=1; i--) suf[i]=max((i==n?0ll:suf[i+1]),a[i].S);
        for (int i=1; i<=n; i++){
            if (i!=n && suf[i+1]>=a[i].F){
                ans=min(ans,suf[i+1]-a[i].F);
                s.insert(a[i].S); continue;
            }
            if (i!=n) ans=min(ans,abs(a[i].F-suf[i+1]));
            auto it=s.lower_bound(a[i].F);
            if (it!=s.end()){
                // printf("--->%lld\n",*it);
                ans=min(ans,abs((*it)-a[i].F));
            }
            if (it!=s.begin()){
                it--;
                // printf("==>%lld\n",*it);
                ans=min(ans,abs(max(suf[i+1],(*it))-a[i].F));
            }
            s.insert(a[i].S);
        }
        for (int i=1; i<=n; i++) suf[i]=0;
        printf("%lld\n",ans); s.clear();
    }
}
/*
1
2
18 4
17 4
*/

詳細信息

Test #1:

score: 100
Accepted
time: 267ms
memory: 10824kb

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