QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#619249#2442. Welcome PartyLavender_Field#WA 166ms7688kbC++201.6kb2024-10-07 13:38:542024-10-07 13:38:54

Judging History

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

  • [2024-10-07 13:38:54]
  • 评测
  • 测评结果:WA
  • 用时:166ms
  • 内存:7688kb
  • [2024-10-07 13:38:54]
  • 提交

answer

#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=a;i<=b;++i)
#define ROF(i,a,b) for(int i=a;i>=b;--i)
typedef long long ll;
using namespace std;
inline int rd() {
    int r = 0; bool w = false; char ch = getchar();
    while( ch < '0' || ch > '9' ) w = !(ch^45), ch = getchar();
    while( ch >= '0' && ch <= '9' ) r = (r<<1) + (r<<3) + (ch^48), ch = getchar();
    return w ? -r : r;
}

#define MAXN 100000
const ll INF = 1e18+1;
int n;
struct node {
    ll a, b;
}r[MAXN+5];
bool cmp(node x , node y) {
    return x.a < y.a;
}
ll rmax[MAXN+5];
priority_queue<ll, vector<ll>, greater<ll> > q1;
priority_queue<ll> q2;
void solve() {
    n = rd();
    FOR(i,1,n) r[i].a = rd(), r[i].b = rd();
    sort(r+1, r+1+n, cmp);
    ROF(i,n,1) rmax[i] = max(rmax[i+1], r[i].b);
    ll ans = INF;
    for(int i=1;i<=n;++i) {
        while( !q1.empty() && q1.top() < r[i].a ) {
            q2.push(q1.top());
            q1.pop();
        }
        ll cons = rmax[i+1];
        if( cons >= r[i].a ) ans = min(ans, cons - r[i].a);
        else {
            if( i != n ) ans = min(ans, r[i].a - cons);
            if( !q2.empty() ) ans = min(ans, r[i].a - q2.top());
            if( !q1.empty() ) ans = min(ans, q1.top() - r[i].a);
        }
        if( r[i].b >= r[i].a ) q1.push(r[i].b);
        else q2.push(r[i].b);
    }
    printf("%lld\n", ans);
    while( !q1.empty() ) q1.pop();
    while( !q2.empty() ) q2.pop();
    for(int i = 1; i <= n; ++i) rmax[i] = 0;
    ans = INF;
}

int main() {
    int T = rd(); while( T-- ) solve();
    return 0;
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 166ms
memory: 7688kb

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
0
1000000000
0
0
5
0
10
5
10
3
0
10
5
0
5
0
10
5
10
3
0
10
5
0
227224431
751178206
817134268
621036115
552575846
507704597
20455370
407439590
370094097
138022625
584548454
112341371
848943178
133505742
7829291
631290681
350219143
331371108
69508481
526779336
176221477
550674167
11...

result:

wrong answer 6th lines differ - expected: '1000000000', found: '0'