Submission #908683

# Submission time Handle Problem Language Result Execution time Memory
908683 2024-01-16T16:30:15 Z Shayan86 Triple Jump (JOI19_jumps) C++14
100 / 100
885 ms 80060 KB
#include <bits/stdc++.h>
using namespace std;

#pragma GCC optimize("O3,unroll-loops")
// #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
// Ofast, O0, O1, O2, O3, unroll-loops, fast-math, trapv

typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;

#define Mp          make_pair
#define sep         ' '
#define endl        '\n'
#define F	        first
#define S	        second
#define pb          push_back
#define all(x)      (x).begin(),(x).end()
#define kill(res)	cout << res << '\n', exit(0);
#define set_dec(x)	cout << fixed << setprecision(x);
#define fast_io     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_io     freopen("input.txt", "r", stdin) ; freopen("output.txt", "w", stdout);

#define lid (id*2)
#define rid (id*2+1)
#define mid ((l+r)/2)

const ll N = 5e5 + 50;
const ll Mod = 1e18;

ll n, q, arr[N], res[N];

vector<int> sta;
vector<pii> qu[N];

pll seg[N*4]; ll lz[N*4];

pll merg(pll l, pll r){
    return {max(l.F, r.F), max(l.S, r.S)};
}

void build(int l = 1, int r = n+1, int id = 1){
    if(l+1 == r){
        seg[id].F = seg[id].S = arr[l];
        return;
    }
    build(l, mid, lid);
    build(mid, r, rid);
    seg[id] = merg(seg[lid], seg[rid]);
}

void quex(int id, ll x){
    seg[id].F = max(seg[id].F, seg[id].S + x);
    lz[id] = max(lz[id], x);
}

void relax(int id){
    quex(lid, lz[id]);
    quex(rid, lz[id]);
}

void upd(int ql, int qr, ll x, int l = 1, int r = n+1, int id = 1){
    if(qr <= l || r <= ql) return;
    if(ql <= l && r <= qr){
        quex(id, x); return;
    }
    relax(id);
    upd(ql, qr, x, l, mid, lid);
    upd(ql, qr, x, mid, r, rid);
    seg[id] = merg(seg[lid], seg[rid]);
}

pll get(int ql, int qr, int l = 1, int r = n+1, int id = 1){
    if(qr <= l || r <= ql) return {0, 0};
    if(ql <= l && r <= qr) return seg[id];
    relax(id);
    return max(get(ql, qr, l, mid, lid), get(ql, qr, mid, r, rid));
}

int main(){
    fast_io;

    cin >> n;

    for(int i = 1; i <= n; i++) cin >> arr[i];

    cin >> q;

    for(int i = 1; i <= q; i++){
        int l, r;
        cin >> l >> r;
        qu[l].pb({r, i});
    }

    build();

    sta.pb(n);
    for(int i = n-1; i >= 1; i--){
        while(!sta.empty()){
            int lst = sta.back(); sta.pop_back();
            upd(lst + lst - i, n+1, arr[i] + arr[lst]);

            if(arr[lst] >= arr[i]){
                sta.pb(lst); break;
            }
        }
        sta.pb(i);

        for(auto [j, id]: qu[i]) res[id] = get(i, j+1).F;
    }

    for(int i = 1; i <= q; i++) cout << res[i] << endl;


}

Compilation message

jumps.cpp: In function 'int main()':
jumps.cpp:109:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
  109 |         for(auto [j, id]: qu[i]) res[id] = get(i, j+1).F;
      |                  ^
# Verdict Execution time Memory Grader output
1 Correct 6 ms 18776 KB Output is correct
2 Correct 6 ms 18780 KB Output is correct
3 Correct 6 ms 18776 KB Output is correct
4 Correct 5 ms 18780 KB Output is correct
5 Correct 6 ms 18944 KB Output is correct
6 Correct 4 ms 18780 KB Output is correct
7 Correct 5 ms 18776 KB Output is correct
8 Correct 6 ms 18776 KB Output is correct
9 Correct 5 ms 18780 KB Output is correct
10 Correct 5 ms 18780 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 18776 KB Output is correct
2 Correct 6 ms 18780 KB Output is correct
3 Correct 6 ms 18776 KB Output is correct
4 Correct 5 ms 18780 KB Output is correct
5 Correct 6 ms 18944 KB Output is correct
6 Correct 4 ms 18780 KB Output is correct
7 Correct 5 ms 18776 KB Output is correct
8 Correct 6 ms 18776 KB Output is correct
9 Correct 5 ms 18780 KB Output is correct
10 Correct 5 ms 18780 KB Output is correct
11 Correct 279 ms 37616 KB Output is correct
12 Correct 214 ms 37580 KB Output is correct
13 Correct 211 ms 37636 KB Output is correct
14 Correct 207 ms 37712 KB Output is correct
15 Correct 224 ms 37592 KB Output is correct
16 Correct 211 ms 37112 KB Output is correct
17 Correct 212 ms 37072 KB Output is correct
18 Correct 231 ms 37064 KB Output is correct
19 Correct 212 ms 37464 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 89 ms 34896 KB Output is correct
2 Correct 58 ms 35944 KB Output is correct
3 Correct 57 ms 35188 KB Output is correct
4 Correct 90 ms 34900 KB Output is correct
5 Correct 89 ms 34900 KB Output is correct
6 Correct 91 ms 34204 KB Output is correct
7 Correct 89 ms 34228 KB Output is correct
8 Correct 98 ms 34036 KB Output is correct
9 Correct 89 ms 34584 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 18776 KB Output is correct
2 Correct 6 ms 18780 KB Output is correct
3 Correct 6 ms 18776 KB Output is correct
4 Correct 5 ms 18780 KB Output is correct
5 Correct 6 ms 18944 KB Output is correct
6 Correct 4 ms 18780 KB Output is correct
7 Correct 5 ms 18776 KB Output is correct
8 Correct 6 ms 18776 KB Output is correct
9 Correct 5 ms 18780 KB Output is correct
10 Correct 5 ms 18780 KB Output is correct
11 Correct 279 ms 37616 KB Output is correct
12 Correct 214 ms 37580 KB Output is correct
13 Correct 211 ms 37636 KB Output is correct
14 Correct 207 ms 37712 KB Output is correct
15 Correct 224 ms 37592 KB Output is correct
16 Correct 211 ms 37112 KB Output is correct
17 Correct 212 ms 37072 KB Output is correct
18 Correct 231 ms 37064 KB Output is correct
19 Correct 212 ms 37464 KB Output is correct
20 Correct 89 ms 34896 KB Output is correct
21 Correct 58 ms 35944 KB Output is correct
22 Correct 57 ms 35188 KB Output is correct
23 Correct 90 ms 34900 KB Output is correct
24 Correct 89 ms 34900 KB Output is correct
25 Correct 91 ms 34204 KB Output is correct
26 Correct 89 ms 34228 KB Output is correct
27 Correct 98 ms 34036 KB Output is correct
28 Correct 89 ms 34584 KB Output is correct
29 Correct 885 ms 74044 KB Output is correct
30 Correct 717 ms 75976 KB Output is correct
31 Correct 739 ms 74116 KB Output is correct
32 Correct 833 ms 74140 KB Output is correct
33 Correct 759 ms 74072 KB Output is correct
34 Correct 790 ms 71764 KB Output is correct
35 Correct 793 ms 71560 KB Output is correct
36 Correct 813 ms 71668 KB Output is correct
37 Correct 788 ms 72980 KB Output is correct
38 Correct 461 ms 79808 KB Output is correct
39 Correct 470 ms 80060 KB Output is correct
40 Correct 468 ms 76724 KB Output is correct
41 Correct 449 ms 75856 KB Output is correct
42 Correct 457 ms 76084 KB Output is correct
43 Correct 453 ms 77900 KB Output is correct
44 Correct 502 ms 79224 KB Output is correct
45 Correct 506 ms 79268 KB Output is correct
46 Correct 492 ms 76128 KB Output is correct
47 Correct 494 ms 75756 KB Output is correct
48 Correct 490 ms 75688 KB Output is correct
49 Correct 492 ms 77728 KB Output is correct
50 Correct 587 ms 77212 KB Output is correct
51 Correct 613 ms 77648 KB Output is correct
52 Correct 596 ms 74836 KB Output is correct
53 Correct 591 ms 74744 KB Output is correct
54 Correct 583 ms 74576 KB Output is correct
55 Correct 575 ms 76204 KB Output is correct