답안 #823471

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
823471 2023-08-12T14:45:08 Z Cookie 3단 점프 (JOI19_jumps) C++14
100 / 100
1014 ms 105464 KB
#include<bits/stdc++.h>
#include<fstream>
using namespace std;
ifstream fin("VNOICUP.INP");
ofstream fout("VNOICUP.OUT");
#define sz(a) (int)a.size()
#define ll long long
#define pb push_back
#define forr(i, a, b) for(int i = a; i < b; i++)
#define dorr(i, a, b) for(int i = a; i >= b; i--)
#define ld long double
#define vt vector
#include<fstream>
#define fi first
#define se second
#define pll pair<ll, ll>
#define pii pair<int, int>
const ld PI = 3.14159265359;
using u128 = __uint128_t;
//const int x[4] = {1, -1, 0, 0};
//const int y[4] = {0, 0, 1, -1};
const ll mod = 1e9 + 7;
const int mxn = 5e5 + 5, mxm = 1e5, sq = 400, mxv = 1e6 + 5;
const int base = (1 << 18);
const ll inf = 4e9, neg = -69420, test = 1e5;
//const int p[12] = {2, 3, 5, 7, 11, 13, 17, 19, 23,  29, 31, 37};bool ck[mxn + 1];
struct Node{
    ll ab = -inf, abc = -inf, lz = -inf;
};
ll a[mxn + 5], ans[mxn + 5];
vt<pii>special[mxn + 1], queries[mxn + 1];
Node st[4 * mxn + 1];
 
void change(int nd, ll c){
    st[nd].lz = max(st[nd].lz, c);
    st[nd].abc = max(st[nd].abc, st[nd].ab + c);
}
void push(int nd){
    change(nd << 1, st[nd].lz); change(nd << 1 | 1, st[nd].lz);
    st[nd].lz = -inf;
}
void upd(int nd, int l, int r, int id, ll v){
    if(id < l || id > r)return;
    if(l == r){
        st[nd].ab = max(st[nd].ab, v);
        return;
    }
    int mid = (l + r) >> 1;
    push(nd);
    upd(nd << 1, l, mid, id, v); upd(nd << 1 | 1, mid + 1, r, id, v);
    st[nd].ab = max(st[nd << 1].ab, st[nd << 1 | 1].ab);
}
void updc(int nd, int l, int r, int ql, int qr, ll v){
    if(ql > r || qr < l)return;
    if(ql <= l && qr >= r){
        change(nd, v);
        return;
    }
    int mid = (l + r) >> 1;
    push(nd);
    updc(nd << 1, l, mid, ql, qr, v); updc(nd << 1 | 1, mid + 1, r, ql, qr, v);
    st[nd].abc = max(st[nd << 1].abc, st[nd << 1 | 1].abc);
}
ll get(int nd, int l, int r, int ql, int qr){
    if(ql > r || qr < l)return(-inf);
    if(ql <= l && qr >= r){
        return(st[nd].abc);
    }
    int mid = (l + r) >> 1;
    push(nd);
    return(max(get(nd << 1, l, mid, ql, qr), get(nd << 1 | 1, mid + 1, r, ql, qr)));
}
int n;
signed main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n;
    for(int i = 1; i <= n; i++)cin >> a[i];
    deque<int>dq;
    for(int i = 1; i <= n; i++){
        while(sz(dq)){
            int j = dq.back();
            special[i * 2 - j].pb(make_pair(j, a[j] + a[i]));
            if(a[i] < a[j])break;
            dq.pop_back();
        }
        dq.pb(i);
    }
    int q; cin >> q;
    for(int i = 0; i < q; i++){
        int l, r; cin >> l >> r;
        queries[r].pb({l, i});
    }
    for(int i = 1; i <= n; i++){
        for(auto j: special[i]){
            //cout << i << " " << j.first << ' ' << j.second << "\n";
            upd(1, 1, n, j.first, j.second);
        }
        updc(1, 1, n, 1, i, a[i]);
        for(auto [l, id]: queries[i]){
            ans[id] = get(1, 1, n, l, i);
        }
    }
    for(int i = 0; i < q; i++){
        cout << ans[i] << "\n";
    }
    return(0);
}

Compilation message

jumps.cpp: In function 'int main()':
jumps.cpp:99:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   99 |         for(auto [l, id]: queries[i]){
      |                  ^
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 23764 KB Output is correct
2 Correct 9 ms 23764 KB Output is correct
3 Correct 10 ms 23764 KB Output is correct
4 Correct 9 ms 23764 KB Output is correct
5 Correct 11 ms 23764 KB Output is correct
6 Correct 10 ms 23764 KB Output is correct
7 Correct 12 ms 23764 KB Output is correct
8 Correct 12 ms 23764 KB Output is correct
9 Correct 10 ms 23764 KB Output is correct
10 Correct 10 ms 23764 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 23764 KB Output is correct
2 Correct 9 ms 23764 KB Output is correct
3 Correct 10 ms 23764 KB Output is correct
4 Correct 9 ms 23764 KB Output is correct
5 Correct 11 ms 23764 KB Output is correct
6 Correct 10 ms 23764 KB Output is correct
7 Correct 12 ms 23764 KB Output is correct
8 Correct 12 ms 23764 KB Output is correct
9 Correct 10 ms 23764 KB Output is correct
10 Correct 10 ms 23764 KB Output is correct
11 Correct 229 ms 40224 KB Output is correct
12 Correct 220 ms 40068 KB Output is correct
13 Correct 223 ms 40208 KB Output is correct
14 Correct 248 ms 40172 KB Output is correct
15 Correct 224 ms 40204 KB Output is correct
16 Correct 237 ms 39604 KB Output is correct
17 Correct 230 ms 39536 KB Output is correct
18 Correct 240 ms 39448 KB Output is correct
19 Correct 230 ms 40160 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 191 ms 44660 KB Output is correct
2 Correct 124 ms 45656 KB Output is correct
3 Correct 118 ms 46520 KB Output is correct
4 Correct 164 ms 46412 KB Output is correct
5 Correct 166 ms 46380 KB Output is correct
6 Correct 162 ms 45772 KB Output is correct
7 Correct 171 ms 45724 KB Output is correct
8 Correct 170 ms 45680 KB Output is correct
9 Correct 189 ms 46020 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 23764 KB Output is correct
2 Correct 9 ms 23764 KB Output is correct
3 Correct 10 ms 23764 KB Output is correct
4 Correct 9 ms 23764 KB Output is correct
5 Correct 11 ms 23764 KB Output is correct
6 Correct 10 ms 23764 KB Output is correct
7 Correct 12 ms 23764 KB Output is correct
8 Correct 12 ms 23764 KB Output is correct
9 Correct 10 ms 23764 KB Output is correct
10 Correct 10 ms 23764 KB Output is correct
11 Correct 229 ms 40224 KB Output is correct
12 Correct 220 ms 40068 KB Output is correct
13 Correct 223 ms 40208 KB Output is correct
14 Correct 248 ms 40172 KB Output is correct
15 Correct 224 ms 40204 KB Output is correct
16 Correct 237 ms 39604 KB Output is correct
17 Correct 230 ms 39536 KB Output is correct
18 Correct 240 ms 39448 KB Output is correct
19 Correct 230 ms 40160 KB Output is correct
20 Correct 191 ms 44660 KB Output is correct
21 Correct 124 ms 45656 KB Output is correct
22 Correct 118 ms 46520 KB Output is correct
23 Correct 164 ms 46412 KB Output is correct
24 Correct 166 ms 46380 KB Output is correct
25 Correct 162 ms 45772 KB Output is correct
26 Correct 171 ms 45724 KB Output is correct
27 Correct 170 ms 45680 KB Output is correct
28 Correct 189 ms 46020 KB Output is correct
29 Correct 941 ms 99732 KB Output is correct
30 Correct 770 ms 97740 KB Output is correct
31 Correct 850 ms 99844 KB Output is correct
32 Correct 908 ms 99828 KB Output is correct
33 Correct 950 ms 99668 KB Output is correct
34 Correct 891 ms 97408 KB Output is correct
35 Correct 899 ms 97320 KB Output is correct
36 Correct 1014 ms 97168 KB Output is correct
37 Correct 953 ms 98520 KB Output is correct
38 Correct 669 ms 105460 KB Output is correct
39 Correct 698 ms 105464 KB Output is correct
40 Correct 678 ms 102056 KB Output is correct
41 Correct 692 ms 101616 KB Output is correct
42 Correct 707 ms 101684 KB Output is correct
43 Correct 675 ms 103268 KB Output is correct
44 Correct 707 ms 104808 KB Output is correct
45 Correct 702 ms 104808 KB Output is correct
46 Correct 715 ms 101724 KB Output is correct
47 Correct 698 ms 101272 KB Output is correct
48 Correct 799 ms 101160 KB Output is correct
49 Correct 778 ms 103372 KB Output is correct
50 Correct 809 ms 103048 KB Output is correct
51 Correct 800 ms 102940 KB Output is correct
52 Correct 761 ms 100440 KB Output is correct
53 Correct 737 ms 100124 KB Output is correct
54 Correct 768 ms 100140 KB Output is correct
55 Correct 768 ms 101916 KB Output is correct