Submission #969881

# Submission time Handle Problem Language Result Execution time Memory
969881 2024-04-25T18:02:30 Z VinhLuu Triple Jump (JOI19_jumps) C++17
100 / 100
776 ms 81764 KB
//#pragma GCC optimize("O3,unroll-loops")
//#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#include <bits/stdc++.h>
//#define int long long
#define ll long long
#define fi first
#define se second
#define pb push_back
#define all(lmao) lmao.begin(), lmao.end()

using namespace std;

typedef pair<ll,ll> pii;
typedef tuple<int,int,int> tp;
const int N = 1e6 + 5;
//const int mod = 1e9 + 7;
const ll oo = 5e18;

int n, a[N], T[N << 2], lz[N << 2], q, kq[N], val[N << 2];

void build(int i,int l,int r){
    if(l == r){
        val[i] = T[i] = a[l];
        return;
    }
    int mid = (l + r) / 2;
    build(i << 1, l, mid);
    build(i << 1|1, mid + 1, r);
    val[i] = T[i] = max(T[i << 1], T[i << 1|1]);
}

void update(int i,int l,int r,int u,int v, int x){
    if(l > r || l > v || r < u) return;
    if(u <= l && r <= v){
        val[i] = max(val[i], T[i] + x);
        lz[i] = max(lz[i], x);
        return;
    }
    if(lz[i]){
        val[i << 1] = max(val[i << 1], T[i << 1] + lz[i]);
        val[i << 1|1] = max(val[i << 1|1], T[i << 1|1] + lz[i]);
        lz[i << 1] = max(lz[i << 1], lz[i]);
        lz[i << 1|1] = max(lz[i << 1|1], lz[i]);
        lz[i] = 0;
    }
    int mid = (l + r) / 2;
    update(i << 1, l, mid, u, v, x);
    update(i << 1|1, mid + 1, r, u, v, x);
    val[i] = max(val[i << 1], val[i << 1|1]);
}

int get(int i,int l,int r,int u,int v){
    if(l > r || l > v || r < u) return 0;
    if(u <= l && r <= v) return val[i];
    if(lz[i]){
        val[i << 1] = max(val[i << 1], T[i << 1] + lz[i]);
        val[i << 1|1] = max(val[i << 1|1], T[i << 1|1] + lz[i]);
        lz[i << 1] = max(lz[i << 1], lz[i]);
        lz[i << 1|1] = max(lz[i << 1|1], lz[i]);
        lz[i] = 0;
    }
    int mid = (l + r) / 2;
    return max(get(i << 1, l, mid, u, v), get(i << 1|1, mid + 1, r, u, v));
}


#define lpv
#ifdef lpv

vector<pii> vr[N];

signed main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    #define task "v"
    if(fopen(task ".inp","r")){
        freopen(task ".inp","r",stdin);
        freopen(task ".out","w",stdout);
    }

    cin >> n;
    for(int i = 1; i <= n; i ++) cin >> a[i];
    cin >> q;
    for(int i = 1; i <= q; i ++){
        int l, r; cin >> l >> r;
        vr[l].pb({r, i});
    }
    stack<int> st;
    build(1, 1, n);
    st.push(n);
    for(int i = n - 1; i >= 1; i --){
        if(i + 2 <= n) update(1, 1, n, i + 2, n, a[i] + a[i + 1]);
        while(!st.empty() && a[i] >= a[st.top()]){
            int tmp = st.top() - i;
            if(st.top() + tmp <= n) update(1, 1, n, st.top() + tmp, n, a[i] + a[st.top()]);
            st.pop();
        }
        if(!st.empty()){
            int tmp = st.top() - i;
            if(st.top() + tmp <= n) update(1, 1, n, st.top() + tmp, n, a[i] + a[st.top()]);
        }
        st.push(i);
        for(auto [j, id] : vr[i]) kq[id] = get(1, 1, n, i + 2, j);

    }
    for(int i = 1; i <= q; i ++) cout << kq[i] << "\n";
}

#endif // lpv

Compilation message

jumps.cpp: In function 'int main()':
jumps.cpp:77:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   77 |         freopen(task ".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
jumps.cpp:78:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   78 |         freopen(task ".out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 11 ms 33368 KB Output is correct
2 Correct 10 ms 33372 KB Output is correct
3 Correct 8 ms 33372 KB Output is correct
4 Correct 7 ms 33368 KB Output is correct
5 Correct 7 ms 33372 KB Output is correct
6 Correct 7 ms 33376 KB Output is correct
7 Correct 8 ms 33372 KB Output is correct
8 Correct 7 ms 33368 KB Output is correct
9 Correct 7 ms 33372 KB Output is correct
10 Correct 7 ms 33372 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 33368 KB Output is correct
2 Correct 10 ms 33372 KB Output is correct
3 Correct 8 ms 33372 KB Output is correct
4 Correct 7 ms 33368 KB Output is correct
5 Correct 7 ms 33372 KB Output is correct
6 Correct 7 ms 33376 KB Output is correct
7 Correct 8 ms 33372 KB Output is correct
8 Correct 7 ms 33368 KB Output is correct
9 Correct 7 ms 33372 KB Output is correct
10 Correct 7 ms 33372 KB Output is correct
11 Correct 194 ms 58388 KB Output is correct
12 Correct 195 ms 58776 KB Output is correct
13 Correct 190 ms 58648 KB Output is correct
14 Correct 188 ms 58444 KB Output is correct
15 Correct 195 ms 58452 KB Output is correct
16 Correct 195 ms 57860 KB Output is correct
17 Correct 189 ms 57940 KB Output is correct
18 Correct 226 ms 57680 KB Output is correct
19 Correct 196 ms 58372 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 121 ms 41068 KB Output is correct
2 Correct 86 ms 41808 KB Output is correct
3 Correct 90 ms 41104 KB Output is correct
4 Correct 122 ms 41076 KB Output is correct
5 Correct 121 ms 41044 KB Output is correct
6 Correct 120 ms 40332 KB Output is correct
7 Correct 124 ms 40388 KB Output is correct
8 Correct 118 ms 40308 KB Output is correct
9 Correct 119 ms 40528 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 33368 KB Output is correct
2 Correct 10 ms 33372 KB Output is correct
3 Correct 8 ms 33372 KB Output is correct
4 Correct 7 ms 33368 KB Output is correct
5 Correct 7 ms 33372 KB Output is correct
6 Correct 7 ms 33376 KB Output is correct
7 Correct 8 ms 33372 KB Output is correct
8 Correct 7 ms 33368 KB Output is correct
9 Correct 7 ms 33372 KB Output is correct
10 Correct 7 ms 33372 KB Output is correct
11 Correct 194 ms 58388 KB Output is correct
12 Correct 195 ms 58776 KB Output is correct
13 Correct 190 ms 58648 KB Output is correct
14 Correct 188 ms 58444 KB Output is correct
15 Correct 195 ms 58452 KB Output is correct
16 Correct 195 ms 57860 KB Output is correct
17 Correct 189 ms 57940 KB Output is correct
18 Correct 226 ms 57680 KB Output is correct
19 Correct 196 ms 58372 KB Output is correct
20 Correct 121 ms 41068 KB Output is correct
21 Correct 86 ms 41808 KB Output is correct
22 Correct 90 ms 41104 KB Output is correct
23 Correct 122 ms 41076 KB Output is correct
24 Correct 121 ms 41044 KB Output is correct
25 Correct 120 ms 40332 KB Output is correct
26 Correct 124 ms 40388 KB Output is correct
27 Correct 118 ms 40308 KB Output is correct
28 Correct 119 ms 40528 KB Output is correct
29 Correct 714 ms 78616 KB Output is correct
30 Correct 635 ms 80656 KB Output is correct
31 Correct 635 ms 78480 KB Output is correct
32 Correct 721 ms 78584 KB Output is correct
33 Correct 742 ms 78836 KB Output is correct
34 Correct 762 ms 76180 KB Output is correct
35 Correct 728 ms 75952 KB Output is correct
36 Correct 776 ms 76116 KB Output is correct
37 Correct 734 ms 77488 KB Output is correct
38 Correct 551 ms 81136 KB Output is correct
39 Correct 566 ms 81284 KB Output is correct
40 Correct 510 ms 77908 KB Output is correct
41 Correct 506 ms 77396 KB Output is correct
42 Correct 515 ms 77516 KB Output is correct
43 Correct 514 ms 79180 KB Output is correct
44 Correct 546 ms 81492 KB Output is correct
45 Correct 554 ms 81568 KB Output is correct
46 Correct 538 ms 78308 KB Output is correct
47 Correct 551 ms 78120 KB Output is correct
48 Correct 542 ms 78000 KB Output is correct
49 Correct 547 ms 79864 KB Output is correct
50 Correct 627 ms 81764 KB Output is correct
51 Correct 642 ms 81744 KB Output is correct
52 Correct 597 ms 79264 KB Output is correct
53 Correct 594 ms 78840 KB Output is correct
54 Correct 659 ms 78792 KB Output is correct
55 Correct 596 ms 80460 KB Output is correct