Submission #990265

# Submission time Handle Problem Language Result Execution time Memory
990265 2024-05-30T04:10:01 Z imarn Constellation 3 (JOI20_constellation3) C++14
100 / 100
237 ms 104004 KB
#include<bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define pii pair<ll,ll>
#define ll long long
#define sz(x) (ll)x.size()
using namespace std;
const int mxn=2e5+5;
pii t[20][mxn];
int up[20][mxn];
int lv[mxn]{0},rv[mxn]{0};
int ti[mxn],to[mxn],cur=0;
ll fw[mxn]{0};
ll dp[mxn]{0};
vector<pii>g[mxn];
void add(int i,ll amt){
    for(;i<mxn;i+=i&-i)fw[i]+=amt;
}
ll qr(int i,ll rs=0){
    for(;i;i-=i&-i)rs+=fw[i];return rs;
}
int get(int l,int r){
    int lg=log2(r-l+1);
    return max(t[lg][l],t[lg][r-(1<<lg)+1]).s;
}
int build(int l,int r){
    if(l==r)return l;
    int m=get(l,r);
    if(m>l)lv[m]=build(l,m-1),up[0][lv[m]]=m;
    if(m<r)rv[m]=build(m+1,r),up[0][rv[m]]=m;
    return m;
}
void dfs(int u){
    ti[u]=++cur;
    if(lv[u])dfs(lv[u]);
    if(rv[u])dfs(rv[u]);
    to[u]=cur;
    if(lv[u]){
        add(ti[u],dp[lv[u]]);
        add(to[u]+1,-dp[lv[u]]);
        add(ti[lv[u]],-dp[lv[u]]);
        add(to[lv[u]]+1,dp[lv[u]]);
    }
    if(rv[u]){
        add(ti[u],dp[rv[u]]);
        add(to[u]+1,-dp[rv[u]]);
        add(ti[rv[u]],-dp[rv[u]]);
        add(to[rv[u]]+1,dp[rv[u]]);
    }dp[u]=dp[lv[u]]+dp[rv[u]];
    for(auto v:g[u]){
        dp[u]=max(dp[u],v.s+qr(ti[v.f]));
    }
}
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);
    int n;cin>>n;
    int a[n+1];for(int i=1;i<=n;i++)cin>>a[i],t[0][i]={a[i],i};
    for(int j=1;j<20;j++)for(int i=1;i+(1<<(j-1))<=n;i++)t[j][i]=max(t[j-1][i],t[j-1][i+(1<<(j-1))]);
    int root=build(1,n);up[0][root]=root;
    for(int j=1;j<20;j++)for(int i=1;i<=n;i++)up[j][i]=up[j-1][up[j-1][i]];
    int m;cin>>m;ll tt=0;
    for(int i=1;i<=m;i++){
        int x,y,c;cin>>x>>y>>c;int u=x;
        for(int j=19;j>=0;j--)if(a[up[j][u]]<y)u=up[j][u];
        g[u].pb({x,c});tt+=c;
    }dfs(root);cout<<tt-dp[root];
}

Compilation message

constellation3.cpp: In function 'long long int qr(int, long long int)':
constellation3.cpp:21:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   21 |     for(;i;i-=i&-i)rs+=fw[i];return rs;
      |     ^~~
constellation3.cpp:21:30: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   21 |     for(;i;i-=i&-i)rs+=fw[i];return rs;
      |                              ^~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 43612 KB Output is correct
2 Correct 5 ms 43612 KB Output is correct
3 Correct 4 ms 43612 KB Output is correct
4 Correct 5 ms 43612 KB Output is correct
5 Correct 5 ms 43612 KB Output is correct
6 Correct 5 ms 43768 KB Output is correct
7 Correct 5 ms 43608 KB Output is correct
8 Correct 5 ms 43612 KB Output is correct
9 Correct 5 ms 43612 KB Output is correct
10 Correct 5 ms 43612 KB Output is correct
11 Correct 4 ms 43708 KB Output is correct
12 Correct 5 ms 43704 KB Output is correct
13 Correct 5 ms 43608 KB Output is correct
14 Correct 5 ms 43676 KB Output is correct
15 Correct 5 ms 43612 KB Output is correct
16 Correct 5 ms 43700 KB Output is correct
17 Correct 5 ms 43612 KB Output is correct
18 Correct 4 ms 43612 KB Output is correct
19 Correct 5 ms 43616 KB Output is correct
20 Correct 5 ms 43612 KB Output is correct
21 Correct 6 ms 43668 KB Output is correct
22 Correct 5 ms 43864 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 43612 KB Output is correct
2 Correct 5 ms 43612 KB Output is correct
3 Correct 4 ms 43612 KB Output is correct
4 Correct 5 ms 43612 KB Output is correct
5 Correct 5 ms 43612 KB Output is correct
6 Correct 5 ms 43768 KB Output is correct
7 Correct 5 ms 43608 KB Output is correct
8 Correct 5 ms 43612 KB Output is correct
9 Correct 5 ms 43612 KB Output is correct
10 Correct 5 ms 43612 KB Output is correct
11 Correct 4 ms 43708 KB Output is correct
12 Correct 5 ms 43704 KB Output is correct
13 Correct 5 ms 43608 KB Output is correct
14 Correct 5 ms 43676 KB Output is correct
15 Correct 5 ms 43612 KB Output is correct
16 Correct 5 ms 43700 KB Output is correct
17 Correct 5 ms 43612 KB Output is correct
18 Correct 4 ms 43612 KB Output is correct
19 Correct 5 ms 43616 KB Output is correct
20 Correct 5 ms 43612 KB Output is correct
21 Correct 6 ms 43668 KB Output is correct
22 Correct 5 ms 43864 KB Output is correct
23 Correct 6 ms 50012 KB Output is correct
24 Correct 6 ms 49904 KB Output is correct
25 Correct 6 ms 50012 KB Output is correct
26 Correct 6 ms 50012 KB Output is correct
27 Correct 6 ms 50012 KB Output is correct
28 Correct 7 ms 50012 KB Output is correct
29 Correct 7 ms 49980 KB Output is correct
30 Correct 6 ms 49776 KB Output is correct
31 Correct 6 ms 49864 KB Output is correct
32 Correct 6 ms 50168 KB Output is correct
33 Correct 6 ms 49900 KB Output is correct
34 Correct 6 ms 50008 KB Output is correct
35 Correct 7 ms 50020 KB Output is correct
36 Correct 7 ms 50012 KB Output is correct
37 Correct 6 ms 50012 KB Output is correct
38 Correct 6 ms 50020 KB Output is correct
39 Correct 6 ms 50012 KB Output is correct
40 Correct 7 ms 50012 KB Output is correct
41 Correct 6 ms 50012 KB Output is correct
42 Correct 6 ms 50012 KB Output is correct
43 Correct 6 ms 50012 KB Output is correct
44 Correct 6 ms 50008 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 43612 KB Output is correct
2 Correct 5 ms 43612 KB Output is correct
3 Correct 4 ms 43612 KB Output is correct
4 Correct 5 ms 43612 KB Output is correct
5 Correct 5 ms 43612 KB Output is correct
6 Correct 5 ms 43768 KB Output is correct
7 Correct 5 ms 43608 KB Output is correct
8 Correct 5 ms 43612 KB Output is correct
9 Correct 5 ms 43612 KB Output is correct
10 Correct 5 ms 43612 KB Output is correct
11 Correct 4 ms 43708 KB Output is correct
12 Correct 5 ms 43704 KB Output is correct
13 Correct 5 ms 43608 KB Output is correct
14 Correct 5 ms 43676 KB Output is correct
15 Correct 5 ms 43612 KB Output is correct
16 Correct 5 ms 43700 KB Output is correct
17 Correct 5 ms 43612 KB Output is correct
18 Correct 4 ms 43612 KB Output is correct
19 Correct 5 ms 43616 KB Output is correct
20 Correct 5 ms 43612 KB Output is correct
21 Correct 6 ms 43668 KB Output is correct
22 Correct 5 ms 43864 KB Output is correct
23 Correct 6 ms 50012 KB Output is correct
24 Correct 6 ms 49904 KB Output is correct
25 Correct 6 ms 50012 KB Output is correct
26 Correct 6 ms 50012 KB Output is correct
27 Correct 6 ms 50012 KB Output is correct
28 Correct 7 ms 50012 KB Output is correct
29 Correct 7 ms 49980 KB Output is correct
30 Correct 6 ms 49776 KB Output is correct
31 Correct 6 ms 49864 KB Output is correct
32 Correct 6 ms 50168 KB Output is correct
33 Correct 6 ms 49900 KB Output is correct
34 Correct 6 ms 50008 KB Output is correct
35 Correct 7 ms 50020 KB Output is correct
36 Correct 7 ms 50012 KB Output is correct
37 Correct 6 ms 50012 KB Output is correct
38 Correct 6 ms 50020 KB Output is correct
39 Correct 6 ms 50012 KB Output is correct
40 Correct 7 ms 50012 KB Output is correct
41 Correct 6 ms 50012 KB Output is correct
42 Correct 6 ms 50012 KB Output is correct
43 Correct 6 ms 50012 KB Output is correct
44 Correct 6 ms 50008 KB Output is correct
45 Correct 216 ms 95944 KB Output is correct
46 Correct 163 ms 95876 KB Output is correct
47 Correct 184 ms 96140 KB Output is correct
48 Correct 190 ms 95828 KB Output is correct
49 Correct 172 ms 96136 KB Output is correct
50 Correct 185 ms 95828 KB Output is correct
51 Correct 175 ms 95740 KB Output is correct
52 Correct 183 ms 96084 KB Output is correct
53 Correct 200 ms 95828 KB Output is correct
54 Correct 225 ms 102228 KB Output is correct
55 Correct 237 ms 100432 KB Output is correct
56 Correct 217 ms 99304 KB Output is correct
57 Correct 231 ms 98756 KB Output is correct
58 Correct 176 ms 99872 KB Output is correct
59 Correct 172 ms 99788 KB Output is correct
60 Correct 103 ms 104004 KB Output is correct
61 Correct 159 ms 94884 KB Output is correct
62 Correct 230 ms 102736 KB Output is correct
63 Correct 167 ms 94636 KB Output is correct
64 Correct 144 ms 94552 KB Output is correct
65 Correct 237 ms 102736 KB Output is correct
66 Correct 157 ms 94660 KB Output is correct