QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#405041#7944. Max Minus Minucup-team992#WA 13ms3752kbC++201.9kb2024-05-05 09:02:532024-05-05 09:02:55

Judging History

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

  • [2024-05-05 09:02:55]
  • 评测
  • 测评结果:WA
  • 用时:13ms
  • 内存:3752kb
  • [2024-05-05 09:02:53]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

#define F first
#define S second
#define ar array
typedef int uci;
#define int long long
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define ll long long
typedef pair<int, int> pii;
typedef vector<int> vi;

void solve(){
    ll N; cin >> N;
    vi A(N); rep(i,0,N) cin >> A[i];

    ll M = A[0], m = A[0];

    rep(i,0,N) {M = max(M,A[i]); m = min(m,A[i]);}

    map<ll, vi> indices;
    rep(i,0,N) indices[A[i]].push_back(i);

    ll ans = M-m;

    ll ML = N+1, MR=-1; for(auto mi: indices[M]) {ML = min(ML, mi); MR = max(MR, mi);}
    ll mL = N+1, mR=-1; for(auto mi: indices[m]) {mL = min(mL, mi); mR = max(mR, mi);}


    ll maxr = -1;
    ll l = N+1;
    ll r = -1;
    for(ll m2 = m; m2 <= (M+m)/2; m2++) {

        ll ol = l, olr=r;
        for(auto i: indices[m2]) {l = min(l,i); r = max(r, i);}

        if(olr<0) {
            rep(i,l,r+1) maxr = max(maxr, A[i]);
        } else {
            rep(i,l,ol) maxr = max(maxr, A[i]);
            rep(i,olr+1,r+1) maxr = max(maxr, A[i]);
        }

        if(maxr + m2 - m + 1 > M) break;

        ans = M-m2-1;
    }
    nextl1:

    ll minr = M+1;
    l = N;
    r = -1;
    for(ll M2 = M; M2 >= (M+m+1)/2; M2--) {
        ll ol = l, olr=r;
        for(auto i: indices[M2]) {l = min(l,i); r = max(r, i);}

        if(olr<0) {
            rep(i,l,r+1) minr = min(minr,A[i]);
        } else {
            rep(i,l,ol) minr = min(minr,A[i]);
            rep(i,olr+1,r+1) minr = min(minr,A[i]);
        }

        if(minr - (M-M2+1) < m) break;

        ans = min(ans, M2-m-1);
    }

    nextl2:

    cout << ans << '\n';

}

uci main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    ll T; cin >> T;
    rep(t,0,T) solve();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3504kb

input:

4
3
42 42 42
4
1 2 2 1
5
1 100 1 100 1
6
1 2 3 4 5 6

output:

0
0
99
2

result:

ok 4 number(s): "0 0 99 2"

Test #2:

score: -100
Wrong Answer
time: 13ms
memory: 3752kb

input:

19530
6
2 3 3 3 4 3
6
2 4 4 2 5 5
6
2 5 2 5 1 3
6
4 4 1 2 4 1
5
5 4 5 3 3
5
2 2 1 5 1
6
3 1 2 4 2 3
5
5 5 4 4 5
6
5 3 3 1 4 2
6
3 3 2 4 2 4
6
1 2 4 5 2 5
5
3 4 5 5 3
6
4 3 3 3 4 3
6
1 5 1 2 3 1
5
5 5 2 1 4
6
1 2 5 3 5 2
6
4 5 2 4 5 2
5
2 4 2 4 1
4
2 3 3 3
6
1 2 2 1 4 5
6
3 2 1 3 3 2
6
2 1 1 2 5 3
6
...

output:

1
2
3
3
1
1
2
0
3
2
3
1
1
2
1
2
3
2
0
1
1
2
0
3
2
2
3
2
2
2
3
3
2
2
1
2
2
2
2
2
2
1
2
1
2
1
2
2
2
1
1
2
2
1
2
2
1
1
1
2
1
2
2
1
2
2
3
2
2
1
1
2
1
2
3
2
0
2
1
1
2
1
1
2
2
2
1
3
2
1
2
3
2
1
1
2
2
3
1
1
1
2
2
1
1
1
1
2
2
2
2
2
3
2
1
2
1
1
1
1
1
1
1
2
2
2
2
2
2
1
2
1
2
4
1
1
1
3
2
2
2
1
2
1
2
1
2
2
1
3
...

result:

wrong answer 117th numbers differ - expected: '0', found: '1'