Submission #242054

# Submission time Handle Problem Language Result Execution time Memory
242054 2020-06-26T16:06:31 Z mhy908 Constellation 3 (JOI20_constellation3) C++14
100 / 100
555 ms 64940 KB
#include <bits/stdc++.h>
#define eb emplace_back
#define mp make_pair
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<int, LL> pil;

struct FENWICK{
    LL tree[200010];
    LL sum(int i){
        LL ans=0;
        while(i){
            ans+=tree[i];
            i-=(i&-i);
        }
        return ans;
    }
    void update(int i, LL num){
        while(i<=200000){
            tree[i]+=num;
            i+=(i&-i);
        }
    }
}fen;
pii tree[800010];
pii f(pii a, pii b){
    pii ret;
    ret.F=max(a.F, b.F);
    if(a.F==ret.F)ret.S=a.S;
    else ret.S=b.S;
    return ret;
}
void update(int point, int s, int e, int num, int val){
    if(s==e){
        tree[point]=mp(val, s);
        return;
    }
    if(num<=(s+e)/2)update(point*2, s, (s+e)/2, num, val);
    else update(point*2+1, (s+e)/2+1, e, num, val);
    tree[point]=f(tree[point*2], tree[point*2+1]);
}
pii query(int point, int s, int e, int a, int b){
    if(a<=s&&e<=b)return tree[point];
    if(e<a||s>b)return mp(-1, 0);
    return f(query(point*2, s, (s+e)/2, a, b), query(point*2+1, (s+e)/2+1, e, a, b));
}
int n, m, re;
vector<pil> arr[200010];
LL dp[400010], sum[400010];
vector<pair<pii, LL> > vc[400010];
set<pair<pii, LL> > s;

int dfs(int l, int r, int t){
    if(l>r)return 0;
    pii tmp=query(1, 1, n, l, r);
    int le=dfs(l, tmp.S-1, tmp.F);
    for(auto i:arr[tmp.S])s.insert(mp(mp(i.F, tmp.S), i.S));
    int ri=dfs(tmp.S+1, r, tmp.F);
    fen.update(l, sum[le]+dp[ri]);
    fen.update(tmp.S, -sum[le]+dp[le]);
    fen.update(tmp.S+1, sum[ri]-dp[ri]);
    fen.update(r+1, -dp[le]-sum[ri]);
    ++re;
    auto it=s.begin();
    while(it!=s.end()){
        auto tmp=*it;
        if(tmp.F.F>t)break;
        vc[re].eb(tmp);
        sum[re]+=tmp.S;
        it++;
    }
    for(auto i:vc[re])s.erase(i);
    dp[re]=sum[re]+dp[le]+dp[ri];
    for(auto i:vc[re])dp[re]=min(dp[re], sum[re]-i.S+fen.sum(i.F.S));
    return re;
}

int main(){
    scanf("%d", &n);
    for(int i=1; i<=n; i++){
        int x;
        scanf("%d", &x);
        update(1, 1, n, i, x);
    }
    scanf("%d", &m);
    for(int i=1; i<=m; i++){
        int x, y, c;
        scanf("%d %d %d", &x, &y, &c);
        arr[x].eb(y, (LL)c);
    }
    dfs(1, n, n+1);
    printf("%lld", dp[re]);
}

Compilation message

constellation3.cpp: In function 'int main()':
constellation3.cpp:82:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
     ~~~~~^~~~~~~~~~
constellation3.cpp:85:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &x);
         ~~~~~^~~~~~~~~~
constellation3.cpp:88:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &m);
     ~~~~~^~~~~~~~~~
constellation3.cpp:91:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d %d", &x, &y, &c);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 13 ms 14464 KB Output is correct
2 Correct 13 ms 14592 KB Output is correct
3 Correct 13 ms 14464 KB Output is correct
4 Correct 13 ms 14464 KB Output is correct
5 Correct 13 ms 14464 KB Output is correct
6 Correct 15 ms 14464 KB Output is correct
7 Correct 14 ms 14592 KB Output is correct
8 Correct 13 ms 14464 KB Output is correct
9 Correct 14 ms 14464 KB Output is correct
10 Correct 13 ms 14592 KB Output is correct
11 Correct 13 ms 14592 KB Output is correct
12 Correct 14 ms 14464 KB Output is correct
13 Correct 12 ms 14464 KB Output is correct
14 Correct 13 ms 14464 KB Output is correct
15 Correct 12 ms 14464 KB Output is correct
16 Correct 13 ms 14592 KB Output is correct
17 Correct 13 ms 14592 KB Output is correct
18 Correct 13 ms 14592 KB Output is correct
19 Correct 13 ms 14464 KB Output is correct
20 Correct 13 ms 14464 KB Output is correct
21 Correct 14 ms 14592 KB Output is correct
22 Correct 12 ms 14464 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 14464 KB Output is correct
2 Correct 13 ms 14592 KB Output is correct
3 Correct 13 ms 14464 KB Output is correct
4 Correct 13 ms 14464 KB Output is correct
5 Correct 13 ms 14464 KB Output is correct
6 Correct 15 ms 14464 KB Output is correct
7 Correct 14 ms 14592 KB Output is correct
8 Correct 13 ms 14464 KB Output is correct
9 Correct 14 ms 14464 KB Output is correct
10 Correct 13 ms 14592 KB Output is correct
11 Correct 13 ms 14592 KB Output is correct
12 Correct 14 ms 14464 KB Output is correct
13 Correct 12 ms 14464 KB Output is correct
14 Correct 13 ms 14464 KB Output is correct
15 Correct 12 ms 14464 KB Output is correct
16 Correct 13 ms 14592 KB Output is correct
17 Correct 13 ms 14592 KB Output is correct
18 Correct 13 ms 14592 KB Output is correct
19 Correct 13 ms 14464 KB Output is correct
20 Correct 13 ms 14464 KB Output is correct
21 Correct 14 ms 14592 KB Output is correct
22 Correct 12 ms 14464 KB Output is correct
23 Correct 15 ms 14720 KB Output is correct
24 Correct 16 ms 14720 KB Output is correct
25 Correct 17 ms 14720 KB Output is correct
26 Correct 15 ms 14720 KB Output is correct
27 Correct 15 ms 14720 KB Output is correct
28 Correct 16 ms 14720 KB Output is correct
29 Correct 16 ms 14720 KB Output is correct
30 Correct 16 ms 14720 KB Output is correct
31 Correct 14 ms 14720 KB Output is correct
32 Correct 19 ms 14976 KB Output is correct
33 Correct 16 ms 14976 KB Output is correct
34 Correct 16 ms 14976 KB Output is correct
35 Correct 16 ms 14848 KB Output is correct
36 Correct 15 ms 14848 KB Output is correct
37 Correct 15 ms 14976 KB Output is correct
38 Correct 15 ms 14976 KB Output is correct
39 Correct 16 ms 14720 KB Output is correct
40 Correct 21 ms 14976 KB Output is correct
41 Correct 16 ms 14720 KB Output is correct
42 Correct 16 ms 14720 KB Output is correct
43 Correct 15 ms 14976 KB Output is correct
44 Correct 20 ms 14720 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 14464 KB Output is correct
2 Correct 13 ms 14592 KB Output is correct
3 Correct 13 ms 14464 KB Output is correct
4 Correct 13 ms 14464 KB Output is correct
5 Correct 13 ms 14464 KB Output is correct
6 Correct 15 ms 14464 KB Output is correct
7 Correct 14 ms 14592 KB Output is correct
8 Correct 13 ms 14464 KB Output is correct
9 Correct 14 ms 14464 KB Output is correct
10 Correct 13 ms 14592 KB Output is correct
11 Correct 13 ms 14592 KB Output is correct
12 Correct 14 ms 14464 KB Output is correct
13 Correct 12 ms 14464 KB Output is correct
14 Correct 13 ms 14464 KB Output is correct
15 Correct 12 ms 14464 KB Output is correct
16 Correct 13 ms 14592 KB Output is correct
17 Correct 13 ms 14592 KB Output is correct
18 Correct 13 ms 14592 KB Output is correct
19 Correct 13 ms 14464 KB Output is correct
20 Correct 13 ms 14464 KB Output is correct
21 Correct 14 ms 14592 KB Output is correct
22 Correct 12 ms 14464 KB Output is correct
23 Correct 15 ms 14720 KB Output is correct
24 Correct 16 ms 14720 KB Output is correct
25 Correct 17 ms 14720 KB Output is correct
26 Correct 15 ms 14720 KB Output is correct
27 Correct 15 ms 14720 KB Output is correct
28 Correct 16 ms 14720 KB Output is correct
29 Correct 16 ms 14720 KB Output is correct
30 Correct 16 ms 14720 KB Output is correct
31 Correct 14 ms 14720 KB Output is correct
32 Correct 19 ms 14976 KB Output is correct
33 Correct 16 ms 14976 KB Output is correct
34 Correct 16 ms 14976 KB Output is correct
35 Correct 16 ms 14848 KB Output is correct
36 Correct 15 ms 14848 KB Output is correct
37 Correct 15 ms 14976 KB Output is correct
38 Correct 15 ms 14976 KB Output is correct
39 Correct 16 ms 14720 KB Output is correct
40 Correct 21 ms 14976 KB Output is correct
41 Correct 16 ms 14720 KB Output is correct
42 Correct 16 ms 14720 KB Output is correct
43 Correct 15 ms 14976 KB Output is correct
44 Correct 20 ms 14720 KB Output is correct
45 Correct 355 ms 38980 KB Output is correct
46 Correct 388 ms 38776 KB Output is correct
47 Correct 354 ms 39160 KB Output is correct
48 Correct 339 ms 38624 KB Output is correct
49 Correct 351 ms 38776 KB Output is correct
50 Correct 373 ms 38508 KB Output is correct
51 Correct 327 ms 38776 KB Output is correct
52 Correct 340 ms 39160 KB Output is correct
53 Correct 341 ms 38952 KB Output is correct
54 Correct 476 ms 61560 KB Output is correct
55 Correct 461 ms 56568 KB Output is correct
56 Correct 508 ms 53344 KB Output is correct
57 Correct 456 ms 52136 KB Output is correct
58 Correct 410 ms 58488 KB Output is correct
59 Correct 414 ms 58360 KB Output is correct
60 Correct 241 ms 64692 KB Output is correct
61 Correct 341 ms 39776 KB Output is correct
62 Correct 555 ms 64940 KB Output is correct
63 Correct 335 ms 39428 KB Output is correct
64 Correct 333 ms 38648 KB Output is correct
65 Correct 466 ms 64760 KB Output is correct
66 Correct 338 ms 40116 KB Output is correct