Submission #102092

# Submission time Handle Problem Language Result Execution time Memory
102092 2019-03-22T08:25:42 Z LittleFlowers__ Two Antennas (JOI19_antennas) C++14
100 / 100
1255 ms 63608 KB
#include <bits/stdc++.h>
#define int long long
using namespace std;

const int N=200010,
          INF=1e9;
int n,q;
int h[N],a[N],b[N],l[N],r[N];

int ans[N];
int C[4*N],D[4*N],M[4*N];
vector<int> st[N],ed[N],qry[N];

void trans(int s){
    if(M[s]==INF) return;
    M[2*s]=min(M[2*s],M[s]);        M[2*s+1]=min(M[2*s+1],M[s]);
    D[2*s]=max(D[2*s],C[2*s]-M[s]); D[2*s+1]=max(D[2*s+1],C[2*s+1]-M[s]);
    M[s]=INF;
}
void upd(int s,int l,int r,int i){
    if(l>i||i>r) return;
    if(l==r){
        C[s]=(C[s]==-INF ? h[i] : -INF); return;
    }
    trans(s);
    int m=(l+r)/2;
    upd(2*s,l,m,i); upd(2*s+1,m+1,r,i);
    C[s]=max(C[2*s],C[2*s+1]);
}
void mod(int s,int l,int r,int u,int v,int x){
    if(l>v||u>r||C[s]==-INF) return;
    if(u<=l&&r<=v){
        M[s]=min(M[s],x); D[s]=max(D[s],C[s]-x); return;
    }
    trans(s);
    int m=(l+r)/2;
    mod(2*s,l,m,u,v,x); mod(2*s+1,m+1,r,u,v,x);
    D[s]=max(D[2*s],D[2*s+1]);
}
int que(int s,int l,int r,int u,int v){
    if(l>v||u>r) return -INF;
    if(u<=l&&r<=v){
        return D[s];
    }
    trans(s);
    int m=(l+r)/2;
    return max(que(2*s,l,m,u,v),que(2*s+1,m+1,r,u,v));
}
void solve(){
    for(int i=1;i<=n;++i){
        if(i+a[i]<=n) st[i+a[i]].push_back(i);
        if(i+b[i]<n)  ed[i+b[i]+1].push_back(i);
    }
    for(int i=1;i<=q;++i){
        qry[r[i]+1].push_back(i);
    }

    for(int i=1;i<=4*n;++i){
        C[i]=D[i]=M[i]=-INF; M[i]=-M[i];
    }
    for(int i=1;i<=n+1;++i){
        for(auto t:st[i])  upd(1,1,n,t);
        for(auto t:ed[i])  upd(1,1,n,t);
        for(auto t:qry[i]) ans[t]=max(ans[t],que(1,1,n,l[t],i-1));
        if(i-a[i]>0) mod(1,1,n,max(1ll,i-b[i]),i-a[i],h[i]);
    }
}
signed main(){
    ios_base::sync_with_stdio(false),cin.tie(nullptr);
    //freopen("ANTENNAS.inp","r",stdin);
    //freopen("ANTENNAS.out","w",stdout);
    cin>>n;
    for(int i=1;i<=n;++i){
        cin>>h[i]>>a[i]>>b[i];
    }
    cin>>q;
    for(int i=1;i<=q;++i){
        cin>>l[i]>>r[i];
    }

    fill(ans+1,ans+q+1,-1);

    solve();

    for(int i=1;i<=n+1;++i){
        st[i].clear(); ed[i].clear(); qry[i].clear();
    }
    reverse(h+1,h+n+1); reverse(a+1,a+n+1); reverse(b+1,b+n+1);
    for(int i=1;i<=q;++i){
        l[i]=n-l[i]+1; r[i]=n-r[i]+1; swap(l[i],r[i]);
    }

    solve();

    for(int i=1;i<=q;++i){
        cout<<ans[i]<<"\n";
    }
}
# Verdict Execution time Memory Grader output
1 Correct 17 ms 14592 KB Output is correct
2 Correct 17 ms 14592 KB Output is correct
3 Correct 18 ms 14584 KB Output is correct
4 Correct 17 ms 14592 KB Output is correct
5 Correct 16 ms 14592 KB Output is correct
6 Correct 17 ms 14592 KB Output is correct
7 Correct 17 ms 14592 KB Output is correct
8 Correct 18 ms 14592 KB Output is correct
9 Correct 17 ms 14592 KB Output is correct
10 Correct 19 ms 14592 KB Output is correct
11 Correct 19 ms 14592 KB Output is correct
12 Correct 17 ms 14584 KB Output is correct
13 Correct 18 ms 14584 KB Output is correct
14 Correct 18 ms 14592 KB Output is correct
15 Correct 16 ms 14592 KB Output is correct
16 Correct 17 ms 14592 KB Output is correct
17 Correct 17 ms 14592 KB Output is correct
18 Correct 19 ms 14520 KB Output is correct
19 Correct 14 ms 14592 KB Output is correct
20 Correct 16 ms 14592 KB Output is correct
21 Correct 19 ms 14500 KB Output is correct
22 Correct 18 ms 14592 KB Output is correct
23 Correct 17 ms 14592 KB Output is correct
24 Correct 16 ms 14592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 14592 KB Output is correct
2 Correct 17 ms 14592 KB Output is correct
3 Correct 18 ms 14584 KB Output is correct
4 Correct 17 ms 14592 KB Output is correct
5 Correct 16 ms 14592 KB Output is correct
6 Correct 17 ms 14592 KB Output is correct
7 Correct 17 ms 14592 KB Output is correct
8 Correct 18 ms 14592 KB Output is correct
9 Correct 17 ms 14592 KB Output is correct
10 Correct 19 ms 14592 KB Output is correct
11 Correct 19 ms 14592 KB Output is correct
12 Correct 17 ms 14584 KB Output is correct
13 Correct 18 ms 14584 KB Output is correct
14 Correct 18 ms 14592 KB Output is correct
15 Correct 16 ms 14592 KB Output is correct
16 Correct 17 ms 14592 KB Output is correct
17 Correct 17 ms 14592 KB Output is correct
18 Correct 19 ms 14520 KB Output is correct
19 Correct 14 ms 14592 KB Output is correct
20 Correct 16 ms 14592 KB Output is correct
21 Correct 19 ms 14500 KB Output is correct
22 Correct 18 ms 14592 KB Output is correct
23 Correct 17 ms 14592 KB Output is correct
24 Correct 16 ms 14592 KB Output is correct
25 Correct 160 ms 23000 KB Output is correct
26 Correct 31 ms 15744 KB Output is correct
27 Correct 229 ms 26260 KB Output is correct
28 Correct 249 ms 26360 KB Output is correct
29 Correct 167 ms 23264 KB Output is correct
30 Correct 147 ms 22648 KB Output is correct
31 Correct 171 ms 25336 KB Output is correct
32 Correct 228 ms 26208 KB Output is correct
33 Correct 232 ms 25720 KB Output is correct
34 Correct 128 ms 20344 KB Output is correct
35 Correct 218 ms 26488 KB Output is correct
36 Correct 265 ms 26196 KB Output is correct
37 Correct 136 ms 21012 KB Output is correct
38 Correct 231 ms 25192 KB Output is correct
39 Correct 53 ms 16376 KB Output is correct
40 Correct 233 ms 25140 KB Output is correct
41 Correct 171 ms 22780 KB Output is correct
42 Correct 214 ms 25212 KB Output is correct
43 Correct 80 ms 18424 KB Output is correct
44 Correct 212 ms 25140 KB Output is correct
45 Correct 47 ms 16632 KB Output is correct
46 Correct 219 ms 25208 KB Output is correct
47 Correct 73 ms 17528 KB Output is correct
48 Correct 234 ms 25360 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 518 ms 45012 KB Output is correct
2 Correct 608 ms 48388 KB Output is correct
3 Correct 442 ms 38264 KB Output is correct
4 Correct 612 ms 48316 KB Output is correct
5 Correct 224 ms 30072 KB Output is correct
6 Correct 578 ms 48272 KB Output is correct
7 Correct 479 ms 43876 KB Output is correct
8 Correct 712 ms 48488 KB Output is correct
9 Correct 73 ms 19832 KB Output is correct
10 Correct 592 ms 48120 KB Output is correct
11 Correct 396 ms 35724 KB Output is correct
12 Correct 637 ms 48368 KB Output is correct
13 Correct 243 ms 47464 KB Output is correct
14 Correct 229 ms 47088 KB Output is correct
15 Correct 257 ms 46308 KB Output is correct
16 Correct 224 ms 46240 KB Output is correct
17 Correct 266 ms 47924 KB Output is correct
18 Correct 355 ms 46664 KB Output is correct
19 Correct 310 ms 47248 KB Output is correct
20 Correct 277 ms 47080 KB Output is correct
21 Correct 260 ms 47084 KB Output is correct
22 Correct 284 ms 46960 KB Output is correct
23 Correct 274 ms 47188 KB Output is correct
24 Correct 323 ms 45792 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 14592 KB Output is correct
2 Correct 17 ms 14592 KB Output is correct
3 Correct 18 ms 14584 KB Output is correct
4 Correct 17 ms 14592 KB Output is correct
5 Correct 16 ms 14592 KB Output is correct
6 Correct 17 ms 14592 KB Output is correct
7 Correct 17 ms 14592 KB Output is correct
8 Correct 18 ms 14592 KB Output is correct
9 Correct 17 ms 14592 KB Output is correct
10 Correct 19 ms 14592 KB Output is correct
11 Correct 19 ms 14592 KB Output is correct
12 Correct 17 ms 14584 KB Output is correct
13 Correct 18 ms 14584 KB Output is correct
14 Correct 18 ms 14592 KB Output is correct
15 Correct 16 ms 14592 KB Output is correct
16 Correct 17 ms 14592 KB Output is correct
17 Correct 17 ms 14592 KB Output is correct
18 Correct 19 ms 14520 KB Output is correct
19 Correct 14 ms 14592 KB Output is correct
20 Correct 16 ms 14592 KB Output is correct
21 Correct 19 ms 14500 KB Output is correct
22 Correct 18 ms 14592 KB Output is correct
23 Correct 17 ms 14592 KB Output is correct
24 Correct 16 ms 14592 KB Output is correct
25 Correct 160 ms 23000 KB Output is correct
26 Correct 31 ms 15744 KB Output is correct
27 Correct 229 ms 26260 KB Output is correct
28 Correct 249 ms 26360 KB Output is correct
29 Correct 167 ms 23264 KB Output is correct
30 Correct 147 ms 22648 KB Output is correct
31 Correct 171 ms 25336 KB Output is correct
32 Correct 228 ms 26208 KB Output is correct
33 Correct 232 ms 25720 KB Output is correct
34 Correct 128 ms 20344 KB Output is correct
35 Correct 218 ms 26488 KB Output is correct
36 Correct 265 ms 26196 KB Output is correct
37 Correct 136 ms 21012 KB Output is correct
38 Correct 231 ms 25192 KB Output is correct
39 Correct 53 ms 16376 KB Output is correct
40 Correct 233 ms 25140 KB Output is correct
41 Correct 171 ms 22780 KB Output is correct
42 Correct 214 ms 25212 KB Output is correct
43 Correct 80 ms 18424 KB Output is correct
44 Correct 212 ms 25140 KB Output is correct
45 Correct 47 ms 16632 KB Output is correct
46 Correct 219 ms 25208 KB Output is correct
47 Correct 73 ms 17528 KB Output is correct
48 Correct 234 ms 25360 KB Output is correct
49 Correct 518 ms 45012 KB Output is correct
50 Correct 608 ms 48388 KB Output is correct
51 Correct 442 ms 38264 KB Output is correct
52 Correct 612 ms 48316 KB Output is correct
53 Correct 224 ms 30072 KB Output is correct
54 Correct 578 ms 48272 KB Output is correct
55 Correct 479 ms 43876 KB Output is correct
56 Correct 712 ms 48488 KB Output is correct
57 Correct 73 ms 19832 KB Output is correct
58 Correct 592 ms 48120 KB Output is correct
59 Correct 396 ms 35724 KB Output is correct
60 Correct 637 ms 48368 KB Output is correct
61 Correct 243 ms 47464 KB Output is correct
62 Correct 229 ms 47088 KB Output is correct
63 Correct 257 ms 46308 KB Output is correct
64 Correct 224 ms 46240 KB Output is correct
65 Correct 266 ms 47924 KB Output is correct
66 Correct 355 ms 46664 KB Output is correct
67 Correct 310 ms 47248 KB Output is correct
68 Correct 277 ms 47080 KB Output is correct
69 Correct 260 ms 47084 KB Output is correct
70 Correct 284 ms 46960 KB Output is correct
71 Correct 274 ms 47188 KB Output is correct
72 Correct 323 ms 45792 KB Output is correct
73 Correct 1074 ms 56572 KB Output is correct
74 Correct 652 ms 49888 KB Output is correct
75 Correct 963 ms 52600 KB Output is correct
76 Correct 1241 ms 63480 KB Output is correct
77 Correct 583 ms 40392 KB Output is correct
78 Correct 1071 ms 59256 KB Output is correct
79 Correct 1203 ms 58672 KB Output is correct
80 Correct 1255 ms 63608 KB Output is correct
81 Correct 488 ms 32248 KB Output is correct
82 Correct 836 ms 56540 KB Output is correct
83 Correct 820 ms 50000 KB Output is correct
84 Correct 1157 ms 63360 KB Output is correct
85 Correct 550 ms 56428 KB Output is correct
86 Correct 778 ms 61168 KB Output is correct
87 Correct 336 ms 48920 KB Output is correct
88 Correct 808 ms 60324 KB Output is correct
89 Correct 676 ms 58844 KB Output is correct
90 Correct 784 ms 60892 KB Output is correct
91 Correct 465 ms 52844 KB Output is correct
92 Correct 813 ms 61164 KB Output is correct
93 Correct 362 ms 50280 KB Output is correct
94 Correct 804 ms 61232 KB Output is correct
95 Correct 405 ms 51636 KB Output is correct
96 Correct 835 ms 59888 KB Output is correct