Submission #202859

# Submission time Handle Problem Language Result Execution time Memory
202859 2020-02-18T10:15:56 Z Mercenary Triple Jump (JOI19_jumps) C++14
46 / 100
1591 ms 91512 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{
    ll 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 = -2e9;
    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 , ll 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);
}
ll 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;
ll 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, ll)':
jumps.cpp:40:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
     int mid = l + r >> 1;
               ~~^~~
jumps.cpp: In function 'll 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 22 ms 23796 KB Output is correct
2 Correct 20 ms 23800 KB Output is correct
3 Correct 21 ms 23928 KB Output is correct
4 Correct 20 ms 24056 KB Output is correct
5 Correct 20 ms 23800 KB Output is correct
6 Correct 20 ms 23800 KB Output is correct
7 Correct 20 ms 23800 KB Output is correct
8 Correct 20 ms 23672 KB Output is correct
9 Correct 19 ms 23800 KB Output is correct
10 Correct 19 ms 23804 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 22 ms 23796 KB Output is correct
2 Correct 20 ms 23800 KB Output is correct
3 Correct 21 ms 23928 KB Output is correct
4 Correct 20 ms 24056 KB Output is correct
5 Correct 20 ms 23800 KB Output is correct
6 Correct 20 ms 23800 KB Output is correct
7 Correct 20 ms 23800 KB Output is correct
8 Correct 20 ms 23672 KB Output is correct
9 Correct 19 ms 23800 KB Output is correct
10 Correct 19 ms 23804 KB Output is correct
11 Correct 417 ms 40312 KB Output is correct
12 Correct 407 ms 40056 KB Output is correct
13 Correct 397 ms 40056 KB Output is correct
14 Correct 390 ms 40124 KB Output is correct
15 Correct 389 ms 40184 KB Output is correct
16 Correct 412 ms 39544 KB Output is correct
17 Correct 381 ms 39416 KB Output is correct
18 Correct 403 ms 39416 KB Output is correct
19 Correct 406 ms 40056 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 229 ms 43768 KB Output is correct
2 Correct 145 ms 43640 KB Output is correct
3 Correct 140 ms 44396 KB Output is correct
4 Correct 254 ms 43896 KB Output is correct
5 Correct 244 ms 43896 KB Output is correct
6 Correct 227 ms 43896 KB Output is correct
7 Correct 218 ms 43768 KB Output is correct
8 Correct 225 ms 43896 KB Output is correct
9 Correct 226 ms 43768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 22 ms 23796 KB Output is correct
2 Correct 20 ms 23800 KB Output is correct
3 Correct 21 ms 23928 KB Output is correct
4 Correct 20 ms 24056 KB Output is correct
5 Correct 20 ms 23800 KB Output is correct
6 Correct 20 ms 23800 KB Output is correct
7 Correct 20 ms 23800 KB Output is correct
8 Correct 20 ms 23672 KB Output is correct
9 Correct 19 ms 23800 KB Output is correct
10 Correct 19 ms 23804 KB Output is correct
11 Correct 417 ms 40312 KB Output is correct
12 Correct 407 ms 40056 KB Output is correct
13 Correct 397 ms 40056 KB Output is correct
14 Correct 390 ms 40124 KB Output is correct
15 Correct 389 ms 40184 KB Output is correct
16 Correct 412 ms 39544 KB Output is correct
17 Correct 381 ms 39416 KB Output is correct
18 Correct 403 ms 39416 KB Output is correct
19 Correct 406 ms 40056 KB Output is correct
20 Correct 229 ms 43768 KB Output is correct
21 Correct 145 ms 43640 KB Output is correct
22 Correct 140 ms 44396 KB Output is correct
23 Correct 254 ms 43896 KB Output is correct
24 Correct 244 ms 43896 KB Output is correct
25 Correct 227 ms 43896 KB Output is correct
26 Correct 218 ms 43768 KB Output is correct
27 Correct 225 ms 43896 KB Output is correct
28 Correct 226 ms 43768 KB Output is correct
29 Correct 1486 ms 85880 KB Output is correct
30 Correct 1212 ms 85292 KB Output is correct
31 Correct 1177 ms 87268 KB Output is correct
32 Correct 1431 ms 85880 KB Output is correct
33 Correct 1591 ms 85880 KB Output is correct
34 Correct 1517 ms 85240 KB Output is correct
35 Correct 1447 ms 85240 KB Output is correct
36 Correct 1508 ms 85244 KB Output is correct
37 Correct 1422 ms 85884 KB Output is correct
38 Correct 1052 ms 91512 KB Output is correct
39 Correct 1050 ms 91512 KB Output is correct
40 Correct 1043 ms 89976 KB Output is correct
41 Correct 995 ms 89720 KB Output is correct
42 Correct 1016 ms 89620 KB Output is correct
43 Correct 1081 ms 90488 KB Output is correct
44 Correct 1118 ms 91008 KB Output is correct
45 Correct 1086 ms 90864 KB Output is correct
46 Correct 1134 ms 89476 KB Output is correct
47 Correct 1109 ms 89276 KB Output is correct
48 Correct 1080 ms 89332 KB Output is correct
49 Correct 1059 ms 90708 KB Output is correct
50 Execution timed out 229 ms 76724 KB Time limit exceeded (wall clock)
51 Halted 0 ms 0 KB -