답안 #404589

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
404589 2021-05-14T17:13:21 Z Lspeed 3단 점프 (JOI19_jumps) C++14
27 / 100
43 ms 4052 KB
#include<bits/stdc++.h>
using namespace std;
using pii = pair<int,int>;

//Let's do sub case 2 first

struct segmentTree
{
    vector<int> val;

    segmentTree(int n)
    {
        for(int i=0;i<2*n;i++)
            val.push_back(0);
    }

    void update(int idx, int v)
    {
        idx = idx + (val.size())/2 - 1;
        val[idx] = v;
        idx /= 2;
        while(idx != 0)
        {
            val[idx] = max(val[2*idx],val[2*idx+1]);
            idx /= 2;
        }
    }

    int ans(int l, int r)
    {
        return ans(1,1,(val.size())/2,l+1,r+1);
    }

    int ans(int idx, int tl, int tr, int l, int r)
    {
        if(l > tr || r < tl)
            return 0;
        if(l <= tl && r >= tr)
            return val[idx];
        int can1 = ans(2*idx,tl,(tl+tr)/2,l,r);
        int can2 = ans(2*idx+1,(tl+tr)/2 +1,tr,l,r);
        //cout<<"ACCESS: "<<idx<<' '<<tl<<' '<<tr<<' '<<l<<' '<<r<<' '<<max(can1,can2)<<endl;
        return max(can1,can2);
    }
};

const int N = 262144;
//segmentTree tree = segmentTree(N);
int ans = 0, mm = 0;
int v[N], save[N];

int main()
{
    int n;
    scanf("%d",&n);
    if(n > N)
        return 0;
    for(int i=0;i<n;i++)
    {
        int a;
        scanf("%d",&a);
        //tree.update(i+1,a);
        v[i] = a;
    }
    vector<pii> vv;
    for(int i=0;i<n;i++)
    {
        mm = max(mm,save[i]);
        ans = max(mm + v[i], ans);
        while(!vv.empty() && vv.back().first <= v[i])
        {
            if(2*i-vv.back().second < n)
                save[2*i-vv.back().second] = max(save[2*i-vv.back().second],vv.back().first+v[i]);
            vv.pop_back();
        }
        vv.push_back({v[i],i});
        if(vv.size() > 1 && 2*i-vv[vv.size()-2].second < n)
            save[2*i-vv[vv.size()-2].second] = max(save[2*i-vv[vv.size()-2].second],vv[vv.size()-2].first+v[i]);
    }
    int q;
    scanf("%d",&q);
    for(int i=0;i<q;i++)
    {
        int l,r;
        scanf("%d%d",&l,&r);
        printf("%d\n",ans);
    }
    return 0;
}

Compilation message

jumps.cpp: In function 'int main()':
jumps.cpp:55:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   55 |     scanf("%d",&n);
      |     ~~~~~^~~~~~~~~
jumps.cpp:61:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   61 |         scanf("%d",&a);
      |         ~~~~~^~~~~~~~~
jumps.cpp:81:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   81 |     scanf("%d",&q);
      |     ~~~~~^~~~~~~~~
jumps.cpp:85:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   85 |         scanf("%d%d",&l,&r);
      |         ~~~~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Incorrect 1 ms 204 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Incorrect 1 ms 204 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 2188 KB Output is correct
2 Correct 33 ms 2208 KB Output is correct
3 Correct 43 ms 4052 KB Output is correct
4 Correct 35 ms 2112 KB Output is correct
5 Correct 32 ms 2228 KB Output is correct
6 Correct 28 ms 2140 KB Output is correct
7 Correct 28 ms 2128 KB Output is correct
8 Correct 27 ms 2116 KB Output is correct
9 Correct 29 ms 2224 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Incorrect 1 ms 204 KB Output isn't correct
3 Halted 0 ms 0 KB -