QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#619381 | #2442. Welcome Party | WorldFinalEscaped# | AC ✓ | 267ms | 10824kb | C++14 | 1.3kb | 2024-10-07 14:02:58 | 2024-10-07 14:03:03 |
Judging History
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