답안 #933287

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
933287 2024-02-25T11:29:33 Z De3b0o 3단 점프 (JOI19_jumps) C++14
27 / 100
59 ms 14800 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[n]=a[l];
        return;
    }
    sb(2*n,l,mid);
    sb(2*n+1,mid+1,r);
    seg[n]=max(seg[2*n],seg[2*n+1]);
}

ll sg(ll n , ll l , ll r , ll l1 , ll r1)
{
    if(l>r1||r<l1)
        return -1e18;
    if(l>=l1&&r<=r1)
        return seg[n];
    return max(sg(2*n,l,mid,l1,r1),sg(2*n+1,mid+1,r,l1,r1));
}

int main()
{
    d3
    ll n1;
    cin >> n1;
    ll a1[n1+1];
    for(int i = 1 ; n1>=i ; i++)
        cin >> a1[i];
    ll q;
    cin >> q;
    while(q--)
    {
        ll l , r;
        cin >> l >> r;
        ll n = r-l+1;
        for(int i = 1 ; n>=i ; i++)
            a[i]=a1[i+l-1];
        sb(1,1,n);
        pll p[n+1];
        pll s[n+1];
        ll mx = -1e18;
        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 = -1e18;
        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 = -1e18;
        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 = -1e18 , ans2 = -1e18;
            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));
        }
        cans
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2596 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2648 KB Output is correct
10 Incorrect 1 ms 2392 KB Output isn't correct
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2596 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2648 KB Output is correct
10 Incorrect 1 ms 2392 KB Output isn't correct
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 59 ms 14416 KB Output is correct
2 Correct 51 ms 14600 KB Output is correct
3 Correct 47 ms 14800 KB Output is correct
4 Correct 52 ms 14428 KB Output is correct
5 Correct 51 ms 14424 KB Output is correct
6 Correct 55 ms 14424 KB Output is correct
7 Correct 53 ms 14424 KB Output is correct
8 Correct 53 ms 14592 KB Output is correct
9 Correct 50 ms 14428 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2596 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2648 KB Output is correct
10 Incorrect 1 ms 2392 KB Output isn't correct
11 Halted 0 ms 0 KB -