Submission #1119150

# Submission time Handle Problem Language Result Execution time Memory
1119150 2024-11-26T16:35:02 Z ttamx Constellation 3 (JOI20_constellation3) C++17
100 / 100
682 ms 74316 KB
#include<bits/stdc++.h>

using namespace std;

using ll = long long;

const int N=2e5+5;
const int K=1<<19;

int n,m;
int a[N];
set<tuple<int,int,int>> star[N];
ll sum;

struct MaxSegtree{
    pair<int,int> t[K];
    void build(int l,int r,int i){
        if(l==r)return void(t[i]={a[l],l});
        int m=(l+r)/2;
        build(l,m,i*2);
        build(m+1,r,i*2+1);
        t[i]=max(t[i*2],t[i*2+1]);
    }
    void build(){
        build(1,n,1);
    }
    pair<int,int> query(int l,int r,int i,int x,int y){
        if(y<l||r<x)return {0,0};
        if(x<=l&&r<=y)return t[i];
        int m=(l+r)/2;
        return max(query(l,m,i*2,x,y),query(m+1,r,i*2+1,x,y));
    }
    pair<int,int> query(int x,int y){
        return query(1,n,1,x,y);
    }
}smx;

struct LazySegtree{
    ll t[K],lz[K];
    void push(int l,int r,int i){
        t[i]+=lz[i];
        if(l<r){
            lz[i*2]+=lz[i];
            lz[i*2+1]+=lz[i];
        }
        lz[i]=0;
    }
    void update(int l,int r,int i,int x,int y,ll v){
        push(l,r,i);
        if(y<l||r<x)return;
        if(x<=l&&r<=y)return lz[i]=v,push(l,r,i);
        int m=(l+r)/2;
        update(l,m,i*2,x,y,v);
        update(m+1,r,i*2+1,x,y,v);
        t[i]=max(t[i*2],t[i*2+1]);
    }
    void update(int x,int y,ll v){
        update(1,n,1,x,y,v);
    }
    ll query(int l,int r,int i,int x,int y){
        push(l,r,i);
        if(y<l||r<x)return 0LL;
        if(x<=l&&r<=y)return t[i];
        int m=(l+r)/2;
        return max(query(l,m,i*2,x,y),query(m+1,r,i*2+1,x,y));
    }
    ll query(int x,int y){
        return query(1,n,1,x,y);
    }
}seg;

void merge(set<tuple<int,int,int>> &a,set<tuple<int,int,int>> &b){
    if(a.size()<b.size())swap(a,b);
    for(auto &e:b)a.emplace(e);
    b.clear();
}

pair<ll,int> solve(int l,int r,int h){
    auto [hh,mid]=smx.query(l,r);
    auto &s=star[mid];
    ll lmx=0,rmx=0;
    if(l<mid){
        auto [mx,id]=solve(l,mid-1,hh);
        merge(s,star[id]);
        lmx=mx;
    }
    if(mid<r){
        auto [mx,id]=solve(mid+1,r,hh);
        merge(s,star[id]);
        rmx=mx;
    }
    seg.update(l,mid,rmx);
    seg.update(mid,r,lmx);
    ll res=seg.query(l,r);
    for(auto it=s.begin();it!=s.end()&&get<0>(*it)<=h;it=s.erase(it)){
        auto [y,x,c]=*it;
        res=max(res,seg.query(x,x)+c);
    }
    return {res,mid};
}

int main(){
    cin.tie(nullptr)->sync_with_stdio(false);
    cin >> n;
    for(int i=1;i<=n;i++){
        cin >> a[i];
    }
    cin >> m;
    for(int i=1;i<=m;i++){
        int x,y,c;
        cin >> x >> y >> c;
        star[x].emplace(y,x,c);
        sum+=c;
    }
    smx.build();
    cout << sum-solve(1,n,n).first;
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 13648 KB Output is correct
2 Correct 4 ms 13648 KB Output is correct
3 Correct 4 ms 13668 KB Output is correct
4 Correct 3 ms 13648 KB Output is correct
5 Correct 4 ms 13660 KB Output is correct
6 Correct 3 ms 13648 KB Output is correct
7 Correct 4 ms 13648 KB Output is correct
8 Correct 4 ms 13648 KB Output is correct
9 Correct 4 ms 13648 KB Output is correct
10 Correct 4 ms 13648 KB Output is correct
11 Correct 4 ms 13868 KB Output is correct
12 Correct 4 ms 13648 KB Output is correct
13 Correct 5 ms 13648 KB Output is correct
14 Correct 3 ms 13648 KB Output is correct
15 Correct 4 ms 13648 KB Output is correct
16 Correct 3 ms 13648 KB Output is correct
17 Correct 3 ms 13648 KB Output is correct
18 Correct 4 ms 13648 KB Output is correct
19 Correct 4 ms 13648 KB Output is correct
20 Correct 4 ms 13768 KB Output is correct
21 Correct 4 ms 13648 KB Output is correct
22 Correct 3 ms 13648 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 13648 KB Output is correct
2 Correct 4 ms 13648 KB Output is correct
3 Correct 4 ms 13668 KB Output is correct
4 Correct 3 ms 13648 KB Output is correct
5 Correct 4 ms 13660 KB Output is correct
6 Correct 3 ms 13648 KB Output is correct
7 Correct 4 ms 13648 KB Output is correct
8 Correct 4 ms 13648 KB Output is correct
9 Correct 4 ms 13648 KB Output is correct
10 Correct 4 ms 13648 KB Output is correct
11 Correct 4 ms 13868 KB Output is correct
12 Correct 4 ms 13648 KB Output is correct
13 Correct 5 ms 13648 KB Output is correct
14 Correct 3 ms 13648 KB Output is correct
15 Correct 4 ms 13648 KB Output is correct
16 Correct 3 ms 13648 KB Output is correct
17 Correct 3 ms 13648 KB Output is correct
18 Correct 4 ms 13648 KB Output is correct
19 Correct 4 ms 13648 KB Output is correct
20 Correct 4 ms 13768 KB Output is correct
21 Correct 4 ms 13648 KB Output is correct
22 Correct 3 ms 13648 KB Output is correct
23 Correct 6 ms 13904 KB Output is correct
24 Correct 7 ms 13904 KB Output is correct
25 Correct 7 ms 13920 KB Output is correct
26 Correct 6 ms 13904 KB Output is correct
27 Correct 7 ms 13904 KB Output is correct
28 Correct 6 ms 13904 KB Output is correct
29 Correct 7 ms 13904 KB Output is correct
30 Correct 7 ms 13904 KB Output is correct
31 Correct 5 ms 13904 KB Output is correct
32 Correct 8 ms 14328 KB Output is correct
33 Correct 8 ms 14160 KB Output is correct
34 Correct 8 ms 13904 KB Output is correct
35 Correct 7 ms 13904 KB Output is correct
36 Correct 6 ms 14164 KB Output is correct
37 Correct 6 ms 14160 KB Output is correct
38 Correct 8 ms 14160 KB Output is correct
39 Correct 6 ms 13904 KB Output is correct
40 Correct 7 ms 14160 KB Output is correct
41 Correct 8 ms 13860 KB Output is correct
42 Correct 8 ms 14008 KB Output is correct
43 Correct 6 ms 14160 KB Output is correct
44 Correct 7 ms 13908 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 13648 KB Output is correct
2 Correct 4 ms 13648 KB Output is correct
3 Correct 4 ms 13668 KB Output is correct
4 Correct 3 ms 13648 KB Output is correct
5 Correct 4 ms 13660 KB Output is correct
6 Correct 3 ms 13648 KB Output is correct
7 Correct 4 ms 13648 KB Output is correct
8 Correct 4 ms 13648 KB Output is correct
9 Correct 4 ms 13648 KB Output is correct
10 Correct 4 ms 13648 KB Output is correct
11 Correct 4 ms 13868 KB Output is correct
12 Correct 4 ms 13648 KB Output is correct
13 Correct 5 ms 13648 KB Output is correct
14 Correct 3 ms 13648 KB Output is correct
15 Correct 4 ms 13648 KB Output is correct
16 Correct 3 ms 13648 KB Output is correct
17 Correct 3 ms 13648 KB Output is correct
18 Correct 4 ms 13648 KB Output is correct
19 Correct 4 ms 13648 KB Output is correct
20 Correct 4 ms 13768 KB Output is correct
21 Correct 4 ms 13648 KB Output is correct
22 Correct 3 ms 13648 KB Output is correct
23 Correct 6 ms 13904 KB Output is correct
24 Correct 7 ms 13904 KB Output is correct
25 Correct 7 ms 13920 KB Output is correct
26 Correct 6 ms 13904 KB Output is correct
27 Correct 7 ms 13904 KB Output is correct
28 Correct 6 ms 13904 KB Output is correct
29 Correct 7 ms 13904 KB Output is correct
30 Correct 7 ms 13904 KB Output is correct
31 Correct 5 ms 13904 KB Output is correct
32 Correct 8 ms 14328 KB Output is correct
33 Correct 8 ms 14160 KB Output is correct
34 Correct 8 ms 13904 KB Output is correct
35 Correct 7 ms 13904 KB Output is correct
36 Correct 6 ms 14164 KB Output is correct
37 Correct 6 ms 14160 KB Output is correct
38 Correct 8 ms 14160 KB Output is correct
39 Correct 6 ms 13904 KB Output is correct
40 Correct 7 ms 14160 KB Output is correct
41 Correct 8 ms 13860 KB Output is correct
42 Correct 8 ms 14008 KB Output is correct
43 Correct 6 ms 14160 KB Output is correct
44 Correct 7 ms 13908 KB Output is correct
45 Correct 385 ms 35196 KB Output is correct
46 Correct 381 ms 40428 KB Output is correct
47 Correct 389 ms 40988 KB Output is correct
48 Correct 384 ms 40160 KB Output is correct
49 Correct 372 ms 40600 KB Output is correct
50 Correct 357 ms 40108 KB Output is correct
51 Correct 366 ms 40472 KB Output is correct
52 Correct 330 ms 41036 KB Output is correct
53 Correct 334 ms 40268 KB Output is correct
54 Correct 602 ms 63664 KB Output is correct
55 Correct 629 ms 57560 KB Output is correct
56 Correct 584 ms 53920 KB Output is correct
57 Correct 534 ms 51736 KB Output is correct
58 Correct 603 ms 56284 KB Output is correct
59 Correct 567 ms 56652 KB Output is correct
60 Correct 300 ms 74316 KB Output is correct
61 Correct 460 ms 40076 KB Output is correct
62 Correct 654 ms 66448 KB Output is correct
63 Correct 466 ms 40304 KB Output is correct
64 Correct 451 ms 39832 KB Output is correct
65 Correct 682 ms 66348 KB Output is correct
66 Correct 420 ms 40480 KB Output is correct