QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#654768#7944. Max Minus MinbabjamalRE 11ms7748kbC++231.9kb2024-10-18 22:06:462024-10-18 22:06:52

Judging History

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

  • [2024-10-18 22:06:52]
  • 评测
  • 测评结果:RE
  • 用时:11ms
  • 内存:7748kb
  • [2024-10-18 22:06:46]
  • 提交

answer

#include<bits/stdc++.h>
#define ll int
#define pb push_back
#define N 200000
#define pll pair<ll,ll>
#define pcl pair<char,ll>
#define x first
#define y second
#define tll tuple<ll,ll,ll>
#define MOD 1000000007
#define inf 2000000000000001ll
#define m_p make_pair
#define pxm pair<ll,map<ll,ll> *>

using namespace std;
//shb


ll n;
ll num[N],mx[2*N][__lg(N)+2],mn[2*N][__lg(N)+2];

ll find_max(ll lt,ll rt)
{
    ll len=rt-lt+1;
    ll k=__lg(len);
    return max(mx[lt][k],mx[rt-(1<<k)+1][k]);
}

ll find_min(ll lt,ll rt)
{
    ll len=rt-lt+1;
    ll k=__lg(len);
    return min(mn[lt][k],mn[rt-(1<<k)+1][k]);
}


ll counter_clockwise(ll lt,ll rt)   //lt--->rt
{
    if(rt<lt)
    {
        rt+=n;
        // swap(lt,rt);
    }
    // cout<<lt<<" "<<rt<<"\n";
    return find_max(lt,rt)-find_min(lt,rt);
}


void solve()
{
    cin>>n;
    for(ll i=0;i<n;i++)
    {
        cin>>num[i];
        mx[i+n][0]=mx[i][0]=
        mn[i+n][0]=mn[i][0]=num[i];
    }
    
    for(ll j=1;j<=__lg(2*n);j++)for(ll i=0;(i+(1<j))<=2*n;i++)
    {
        mx[i][j]=max(mx[i][j-1],mx[i+(1<<(j-1))][j-1]);
        mn[i][j]=min(mn[i][j-1],mn[i+(1<<(j-1))][j-1]);
    }
    ll ans=find_max(0,n-1)-find_min(0,n-1);
    for(ll i=0;i<n;i++)
    {
        ll j=i;
        for(ll x=n-1;x>=1;x/=2)
        {
            while((j+x)<(i+n-1) && counter_clockwise(i,(j+x)%n) <= counter_clockwise((j+x+1)%n,(i-1+n)%n))
                j+=x;
        }
        // cout<<i<<" "<<j<<"\n";
        ans=min(ans,max(counter_clockwise(i,j%n),
        counter_clockwise((j+1)%n,(i-1+n)%n)));
    }
    // cout<<counter_clockwise(3,0)<<"\n";
    cout<<ans<<"\n";


}



int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    // init();
    ll t=1;
    cin>>t;
    // cout<<__lg(1ll<<62)<<endl;
    ll a,b,c,d;
    for(ll i=1;i<=t;i++)
    {
        // cout<<"Case "<<i<<": ";
        solve();
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 0
Accepted
time: 11ms
memory: 5784kb

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
0
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:

ok 19530 numbers

Test #3:

score: -100
Runtime Error

input:

1
199996
95228303 201285494 63848235 748936712 940169142 379639162 189291770 224201078 335564466 792345215 948056869 35198826 312793561 194588099 297198853 665606109 163797196 584404459 996890415 458867609 331820116 713293915 858136035 520976262 519894660 918315819 660535535 639896052 141007070 1151...

output:


result: