답안 #933187

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
933187 2024-02-25T08:46:29 Z De3b0o 3단 점프 (JOI19_jumps) C++14
0 / 100
59 ms 12020 KB
#include<bits/stdc++.h>
#define ll long long
#define F first
#define S second
#define in insert
#define er erase
#define pb push_back
#define ppb pop_back()
#define ph push
#define pp pop()
#define d3 ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define cans cout << ans << "\n";
#define yes cout << "YES" << "\n";
#define no cout << "NO" << "\n";
#define pll pair<ll,ll>
#define lin cout << "\n";
#define sqr 340
#define mod 1000000007
#define mid ((l+r)/2)
#define lc (2*n)
#define rc (2*n+1)

using namespace std;

ll fp(ll x , ll y)
{
    if(y==0)
        return 1;
    ll z = fp(x,y/2);
    if(y&1)
        return z*z*x;
    else
        return z*z;
}

int sqrot(ll x)
{
    int l = 0 , r = INT_MAX;
    while(l<=r)
    {
        if(mid*mid>=x)
            r=mid-1;
        else
            l=mid+1;
    }
    return r+1;
}

ll cel(ll x , ll y)
{
    return x/y + bool(x/y);
}

string tb(ll x)
{
    string s = "";
    while(x>0)
    {
        if(x&1)
            s+='1';
        else
            s+='0';
        x/=2;
    }
    while(s.size()<60)
        s+='0';
    return s;
}

ll fb(string s)
{
    ll x = 0;
    ll c = 1;
    for(int8_t i = 0 ; 60>i ; i++)
    {
        if(s[i]=='1')
            x+=c;
        c*=2;
    }
    return x;
}

ll seg[800009];
ll a[200009];

void sb(ll n , ll l , ll r)
{
    if(l==r)
    {
        seg[l]=a[l];
        return;
    }
    sb(lc,l,mid);
    sb(rc,mid+1,r);
    seg[n]=max(seg[lc],seg[rc]);
}

ll sg(ll n , ll l , ll r , ll l1 , ll r1)
{
    if(l>r1||r<l1)
        return 0;
    if(l>=l1&&r<=r1)
        return seg[n];
    return max(sg(lc,l,mid,l1,r1),sg(rc,mid+1,r,l1,r1));
}

int main()
{
    d3
    ll n;
    cin >> n;
    for(int i = 1 ; n>=i ; i++)
        cin >> a[i];
    sb(1,1,n);
    pll p[n+1];
    pll s[n+1];
    ll mx = 0;
    ll idx = 0;
    for(int i = 1 ; n>=i ; i++)
    {
        if(a[i]>=mx)
        {
            mx=a[i];
            idx=i;
        }
        p[i].F=mx;
        p[i].S=idx;
    }
    mx = 0;
    idx = 0;
    for(int i = n ; i>0 ; i--)
    {
        if(a[i]>mx)
        {
            mx=a[i];
            idx=i;
        }
        s[i].F=mx;
        s[i].S=idx;
    }
    ll ans = 0;
    for(int i = 2 ; n>i ; i++)
    {
        ll x = p[i-1].F;
        ll idx = p[i-1].S;
        ll y = s[i+1].F;
        ll idy = s[i+1].S;
        ll ans1 = 0 , ans2 = 0;
        if(2*i-idx<=n)
            ans1 = x+a[i]+s[2*i-idx].F;
        ll w = 1;
        ans2 = sg(1,1,n,max(2*i-idy,w),i-1)+a[i]+y;
        ans=max(ans,max(ans1,ans2));
    }
    ll q;
    cin >> q;
    while(q--)
    {
        ll l , r;
        cin >> l >> r;
        cout << ans << "\n";
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Incorrect 1 ms 2396 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Incorrect 1 ms 2396 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 59 ms 12020 KB Output is correct
2 Correct 59 ms 11868 KB Output is correct
3 Correct 41 ms 11992 KB Output is correct
4 Correct 50 ms 11864 KB Output is correct
5 Incorrect 50 ms 11864 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Incorrect 1 ms 2396 KB Output isn't correct
3 Halted 0 ms 0 KB -