Submission #328191

# Submission time Handle Problem Language Result Execution time Memory
328191 2020-11-15T16:05:10 Z nickmet2004 Triple Jump (JOI19_jumps) C++11
46 / 100
692 ms 132544 KB
#include<bits/stdc++.h>

using namespace std;
typedef pair<int , int> ipair;
const int N = 5e5 + 5;
int n , q , a[N] , ans[N];
vector<ipair> Q[N];
vector<int> e[N];

void R(){
    stack<int> s;
    for(int i = 1; i <= n; ++i){
        while(!s.empty() && a[i] >= a[s.top()]) e[s.top()].emplace_back(i) , s.pop();
        if(!s.empty()) e[s.top()].emplace_back(i);
        s.push(i);
    }
}
struct Node{
    int mx , f , a;
    Node(int mx =0 , int f = 0 , int a = 0) : mx(mx) , f(f) ,a(a) {}
}T[1<<19];
Node operator+(const Node &A , const Node &B){
    Node ret;
    ret.mx = max({A.mx , A.f + B.a , B.mx});
    ret.a = max(A.a , B.a);
    ret.f = max(A.f , B.f);
    return ret;
}
void B(int l = 1 , int r= n  , int pos = 1){
    if(l == r){
        T[pos].a = a[l]; return;
    }
    int mid = (l + r)>>1;
    B(l , mid , pos *  2 ); B(mid + 1 ,r , pos * 2 + 1);
    T[pos].a = max(T[pos* 2].a , T[pos * 2 + 1].a);
}
void upd(int i , int x , int l = 1 , int r = n  , int pos = 1){
    if(i < l || i > r)return;
    if(l == r){
        T[pos].f = max(T[pos].f , x);
        T[pos].mx = T[pos].f + T[pos].a;
        //T[pos].mx = max(T[pos].mx , x + T[pos].a);
        return;
    }
    int mid = (l + r)>>1;
    if(i <= mid) upd(i ,x , l ,mid,  pos * 2);
    else upd(i ,x , mid +1 , r, pos * 2 + 1);
    T[pos] = T[pos * 2 ] + T[pos * 2 + 1];
}
Node get(int L ,int R , int l = 1 , int r= n  , int pos = 1){
    if(r < L || R < l)return Node();
    if(L <= l && r <= R) return T[pos];
    int mid = (l + r)>>1;
    return get(L , R , l , mid , pos * 2 ) + get(L , R ,mid + 1 , r , pos * 2 + 1);
}
int main (){
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> n;
    for(int i =1; i <= n; ++i)cin >> a[i];
    cin >> q;
    for(int i = 0; i < q; ++i){
        int l , r; cin >> l >> r;
        Q[l].emplace_back(r , i);
    }//cerr<<endl;
    R();
    B();
    //for(auto x : e)cout << x.first << " " << x.second << endl;
    for(int l = n; l; --l){
        for(int x : e[l])if(2 * x - l <= n) upd(2 * x - l , a[l] + a[x]);
        for(auto X : Q[l]){
            int i = X.second , r = X.first;
            ans[i] = get(l , r).mx;
        }
    }
    for(int i= 0; i < q; ++i)cout << ans[i] << " ";
}

# Verdict Execution time Memory Grader output
1 Correct 21 ms 29932 KB Output is correct
2 Correct 22 ms 29932 KB Output is correct
3 Correct 21 ms 29932 KB Output is correct
4 Correct 21 ms 29932 KB Output is correct
5 Correct 21 ms 29932 KB Output is correct
6 Correct 21 ms 29932 KB Output is correct
7 Correct 21 ms 29932 KB Output is correct
8 Correct 21 ms 29932 KB Output is correct
9 Correct 21 ms 29932 KB Output is correct
10 Correct 21 ms 29932 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 29932 KB Output is correct
2 Correct 22 ms 29932 KB Output is correct
3 Correct 21 ms 29932 KB Output is correct
4 Correct 21 ms 29932 KB Output is correct
5 Correct 21 ms 29932 KB Output is correct
6 Correct 21 ms 29932 KB Output is correct
7 Correct 21 ms 29932 KB Output is correct
8 Correct 21 ms 29932 KB Output is correct
9 Correct 21 ms 29932 KB Output is correct
10 Correct 21 ms 29932 KB Output is correct
11 Correct 476 ms 48620 KB Output is correct
12 Correct 477 ms 48532 KB Output is correct
13 Correct 458 ms 48748 KB Output is correct
14 Correct 467 ms 48620 KB Output is correct
15 Correct 476 ms 48876 KB Output is correct
16 Correct 481 ms 48236 KB Output is correct
17 Correct 477 ms 48108 KB Output is correct
18 Correct 471 ms 48108 KB Output is correct
19 Correct 471 ms 48492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 186 ms 37228 KB Output is correct
2 Correct 114 ms 37100 KB Output is correct
3 Correct 115 ms 37868 KB Output is correct
4 Correct 184 ms 39148 KB Output is correct
5 Correct 188 ms 39148 KB Output is correct
6 Correct 180 ms 38380 KB Output is correct
7 Correct 182 ms 38252 KB Output is correct
8 Correct 182 ms 38252 KB Output is correct
9 Correct 186 ms 38636 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 29932 KB Output is correct
2 Correct 22 ms 29932 KB Output is correct
3 Correct 21 ms 29932 KB Output is correct
4 Correct 21 ms 29932 KB Output is correct
5 Correct 21 ms 29932 KB Output is correct
6 Correct 21 ms 29932 KB Output is correct
7 Correct 21 ms 29932 KB Output is correct
8 Correct 21 ms 29932 KB Output is correct
9 Correct 21 ms 29932 KB Output is correct
10 Correct 21 ms 29932 KB Output is correct
11 Correct 476 ms 48620 KB Output is correct
12 Correct 477 ms 48532 KB Output is correct
13 Correct 458 ms 48748 KB Output is correct
14 Correct 467 ms 48620 KB Output is correct
15 Correct 476 ms 48876 KB Output is correct
16 Correct 481 ms 48236 KB Output is correct
17 Correct 477 ms 48108 KB Output is correct
18 Correct 471 ms 48108 KB Output is correct
19 Correct 471 ms 48492 KB Output is correct
20 Correct 186 ms 37228 KB Output is correct
21 Correct 114 ms 37100 KB Output is correct
22 Correct 115 ms 37868 KB Output is correct
23 Correct 184 ms 39148 KB Output is correct
24 Correct 188 ms 39148 KB Output is correct
25 Correct 180 ms 38380 KB Output is correct
26 Correct 182 ms 38252 KB Output is correct
27 Correct 182 ms 38252 KB Output is correct
28 Correct 186 ms 38636 KB Output is correct
29 Runtime error 692 ms 132544 KB Execution killed with signal 11 (could be triggered by violating memory limits)
30 Halted 0 ms 0 KB -