Submission #202861

# Submission time Handle Problem Language Result Execution time Memory
202861 2020-02-18T10:24:48 Z Mercenary Triple Jump (JOI19_jumps) C++14
100 / 100
1415 ms 85396 KB
#include<bits/stdc++.h>
#define taskname "A"
#define pb push_back
#define mp make_pair

using namespace std;
const int maxn = 5e5 + 6;
typedef pair<int,int> ii;
typedef long long ll;
typedef long double ld;
struct node{
    int lz , s , res;
}s[maxn * 4];
int n , a[maxn];
void push(int x , bool key){
    s[x].res = max(s[x].res,s[x].s+s[x].lz);
    if(key){
        s[x * 2].lz=  max(s[x * 2].lz , s[x].lz);
        s[x * 2 + 1].lz = max(s[x * 2 + 1].lz , s[x].lz);
    }
}
void build(int x , int l , int r){
    s[x].lz = -1e9;
    if(l == r){
        s[x].s = a[l];
        return;
    }
    int mid = l + r >> 1;
    build(x*2,l,mid);build(x*2+1,mid+1,r);
    s[x].s = max(s[x*2].s,s[x*2+1].s);
}
void update(int x , int l , int r , int L , int R , int val){
    push(x,l!=r);
    if(L > r || l > R)return;
    if(L <= l && r <= R){
        s[x].lz = max(s[x].lz,val);
        push(x,l!=r);
        return;
    }
    int mid = l + r >> 1;
    update(x*2,l,mid,L,R,val);
    update(x*2+1,mid+1,r,L,R,val);
    s[x].res = max(s[x*2].res,s[x*2+1].res);
}
int query(int x , int l , int r , int L , int R){
    push(x,l!=r);
    if(L > r || l > R)return 0;
    if(L <= l && r <= R)return s[x].res;
    int mid = l + r >> 1;
    return max(query(x*2,l,mid,L,R),query(x*2+1,mid+1,r,L,R));
}
int q;
int ans[maxn];
vector<ii> Q[maxn];
vector<int> U[maxn];

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);
    if(fopen(taskname".INP","r")){
        freopen(taskname".INP","r",stdin);
        freopen(taskname".OUT","w",stdout);
    }
    cin >> n;
    for(int i = 1 ; i <= n ; ++i)cin >> a[i];
    build(1,1,n);
    vector<int> s;
    for(int i = 1 ; i <= n ; ++i){
        while(s.size() && a[s.back()] <= a[i]){
            U[s.back()].pb(i);s.pop_back();
        }
        if(s.size())U[s.back()].pb(i);
        s.pb(i);
    }
    cin >> q;
    for(int i = 1 ; i <= q ; ++i){
        int u , v;cin >> u >> v;Q[u].pb(mp(v,i));
    }
    for(int i = n ; i >= 1 ; --i){
        for(auto & b : U[i]){
            if(b * 2 - i <= n){
                update(1,1,n,b*2-i,n,a[b]+a[i]);
//                cout << i << " " << b << " " << b * 2 - i << endl;
            }
        }
        for(auto & c : Q[i]){
            ans[c.second] = query(1,1,n,i,c.first);
        }
    }
    for(int i = 1 ; i <= q ; ++i)cout << ans[i] <<  '\n';
}

Compilation message

jumps.cpp: In function 'void build(int, int, int)':
jumps.cpp:28:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
     int mid = l + r >> 1;
               ~~^~~
jumps.cpp: In function 'void update(int, int, int, int, int, int)':
jumps.cpp:40:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
     int mid = l + r >> 1;
               ~~^~~
jumps.cpp: In function 'int query(int, int, int, int, int)':
jumps.cpp:49:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
     int mid = l + r >> 1;
               ~~^~~
jumps.cpp: In function 'int main()':
jumps.cpp:60:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
         freopen(taskname".INP","r",stdin);
         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
jumps.cpp:61:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
         freopen(taskname".OUT","w",stdout);
         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 19 ms 23800 KB Output is correct
2 Correct 18 ms 23800 KB Output is correct
3 Correct 19 ms 23800 KB Output is correct
4 Correct 19 ms 23800 KB Output is correct
5 Correct 20 ms 23800 KB Output is correct
6 Correct 19 ms 23800 KB Output is correct
7 Correct 20 ms 23928 KB Output is correct
8 Correct 19 ms 23800 KB Output is correct
9 Correct 20 ms 23800 KB Output is correct
10 Correct 22 ms 24056 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 23800 KB Output is correct
2 Correct 18 ms 23800 KB Output is correct
3 Correct 19 ms 23800 KB Output is correct
4 Correct 19 ms 23800 KB Output is correct
5 Correct 20 ms 23800 KB Output is correct
6 Correct 19 ms 23800 KB Output is correct
7 Correct 20 ms 23928 KB Output is correct
8 Correct 19 ms 23800 KB Output is correct
9 Correct 20 ms 23800 KB Output is correct
10 Correct 22 ms 24056 KB Output is correct
11 Correct 389 ms 37624 KB Output is correct
12 Correct 378 ms 37496 KB Output is correct
13 Correct 360 ms 37496 KB Output is correct
14 Correct 361 ms 37584 KB Output is correct
15 Correct 385 ms 37584 KB Output is correct
16 Correct 366 ms 36856 KB Output is correct
17 Correct 378 ms 36984 KB Output is correct
18 Correct 402 ms 36856 KB Output is correct
19 Correct 370 ms 37496 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 232 ms 37240 KB Output is correct
2 Correct 143 ms 37116 KB Output is correct
3 Correct 151 ms 37868 KB Output is correct
4 Correct 236 ms 37240 KB Output is correct
5 Correct 229 ms 37240 KB Output is correct
6 Correct 234 ms 37368 KB Output is correct
7 Correct 217 ms 37240 KB Output is correct
8 Correct 222 ms 37240 KB Output is correct
9 Correct 222 ms 37368 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 23800 KB Output is correct
2 Correct 18 ms 23800 KB Output is correct
3 Correct 19 ms 23800 KB Output is correct
4 Correct 19 ms 23800 KB Output is correct
5 Correct 20 ms 23800 KB Output is correct
6 Correct 19 ms 23800 KB Output is correct
7 Correct 20 ms 23928 KB Output is correct
8 Correct 19 ms 23800 KB Output is correct
9 Correct 20 ms 23800 KB Output is correct
10 Correct 22 ms 24056 KB Output is correct
11 Correct 389 ms 37624 KB Output is correct
12 Correct 378 ms 37496 KB Output is correct
13 Correct 360 ms 37496 KB Output is correct
14 Correct 361 ms 37584 KB Output is correct
15 Correct 385 ms 37584 KB Output is correct
16 Correct 366 ms 36856 KB Output is correct
17 Correct 378 ms 36984 KB Output is correct
18 Correct 402 ms 36856 KB Output is correct
19 Correct 370 ms 37496 KB Output is correct
20 Correct 232 ms 37240 KB Output is correct
21 Correct 143 ms 37116 KB Output is correct
22 Correct 151 ms 37868 KB Output is correct
23 Correct 236 ms 37240 KB Output is correct
24 Correct 229 ms 37240 KB Output is correct
25 Correct 234 ms 37368 KB Output is correct
26 Correct 217 ms 37240 KB Output is correct
27 Correct 222 ms 37240 KB Output is correct
28 Correct 222 ms 37368 KB Output is correct
29 Correct 1388 ms 71324 KB Output is correct
30 Correct 1134 ms 70648 KB Output is correct
31 Correct 1176 ms 72548 KB Output is correct
32 Correct 1385 ms 71160 KB Output is correct
33 Correct 1415 ms 71288 KB Output is correct
34 Correct 1365 ms 70616 KB Output is correct
35 Correct 1389 ms 70648 KB Output is correct
36 Correct 1333 ms 70520 KB Output is correct
37 Correct 1395 ms 71160 KB Output is correct
38 Correct 1053 ms 77052 KB Output is correct
39 Correct 1038 ms 77052 KB Output is correct
40 Correct 1008 ms 75260 KB Output is correct
41 Correct 978 ms 75080 KB Output is correct
42 Correct 1030 ms 75032 KB Output is correct
43 Correct 1030 ms 75924 KB Output is correct
44 Correct 1157 ms 76216 KB Output is correct
45 Correct 1053 ms 76392 KB Output is correct
46 Correct 1080 ms 74876 KB Output is correct
47 Correct 1064 ms 74616 KB Output is correct
48 Correct 1061 ms 74744 KB Output is correct
49 Correct 1111 ms 75860 KB Output is correct
50 Correct 1160 ms 77460 KB Output is correct
51 Correct 1151 ms 85396 KB Output is correct
52 Correct 1171 ms 82936 KB Output is correct
53 Correct 1163 ms 82680 KB Output is correct
54 Correct 1177 ms 82552 KB Output is correct
55 Correct 1122 ms 84216 KB Output is correct