Submission #946949

# Submission time Handle Problem Language Result Execution time Memory
946949 2024-03-15T08:04:35 Z phoenix0423 Constellation 3 (JOI20_constellation3) C++17
100 / 100
158 ms 32976 KB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
#define fastio ios::sync_with_stdio(false), cin.tie(0)
#define pb push_back
#define eb emplace_back
#define f first
#define s second
#define int long long 
#define lowbit(x) x&-x
const int maxn = 2e5 + 5;
int BIT[maxn];
int l[maxn], r[maxn], h[maxn];
vector<int> mg[maxn];
vector<pll> star[maxn];
int n;

void upd(int pos, int val){
    while(pos < maxn){
        BIT[pos] += val;
        pos += lowbit(pos);
    }
}

int qry(int pos){
    if(pos < 0) return 0;
    int ret = 0;
    while(pos){
        ret += BIT[pos];
        pos -= lowbit(pos);
    }
    return ret;
}
int rootl(int x){ return l[x] == x ? l[x] : l[x] = rootl(l[x]);}
int rootr(int x){ return r[x] == x ? r[x] : r[x] = rootr(r[x]);}
void merge(int a, int b){
    l[b] = rootl(a);
    r[a] = rootr(b);
}

signed main(void){
    fastio;
    cin>>n;
    for(int i = 1; i <= n; i++) l[i] = r[i] = i;
    for(int i = 1; i <= n; i++){
        cin>>h[i];
        mg[h[i]].pb(i);
    }
    int m;
    cin>>m;
    for(int i = 0; i < m; i++){
        int a, b, w;
        cin>>a>>b>>w;
        star[b].eb(a, w);
    }
    int ans = 0;
    for(int i = 1; i <= n; i++){
        for(auto [x, w] : star[i]){
            l[x] = rootl(l[x]), r[x] = rootr(r[x]);
            int val = qry(x);
            if(val > w) ans += w;
            else ans += val, upd(l[x], w - val), upd(r[x] + 1, val - w);
        }
        for(auto x : mg[i]){
            if(x > 1 && h[x - 1] <= h[x]) merge(x - 1, x);
            if(x < n && h[x + 1] <= h[x]) merge(x, x + 1);
        }
    }
    cout<<ans<<"\n";
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 14936 KB Output is correct
2 Correct 3 ms 14940 KB Output is correct
3 Correct 3 ms 15028 KB Output is correct
4 Correct 3 ms 14940 KB Output is correct
5 Correct 3 ms 14936 KB Output is correct
6 Correct 3 ms 14940 KB Output is correct
7 Correct 3 ms 14936 KB Output is correct
8 Correct 3 ms 14940 KB Output is correct
9 Correct 3 ms 14940 KB Output is correct
10 Correct 4 ms 14940 KB Output is correct
11 Correct 3 ms 14936 KB Output is correct
12 Correct 3 ms 14940 KB Output is correct
13 Correct 3 ms 14940 KB Output is correct
14 Correct 3 ms 14940 KB Output is correct
15 Correct 3 ms 14940 KB Output is correct
16 Correct 4 ms 14940 KB Output is correct
17 Correct 3 ms 14940 KB Output is correct
18 Correct 3 ms 14936 KB Output is correct
19 Correct 3 ms 14936 KB Output is correct
20 Correct 3 ms 14940 KB Output is correct
21 Correct 3 ms 14940 KB Output is correct
22 Correct 4 ms 14944 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 14936 KB Output is correct
2 Correct 3 ms 14940 KB Output is correct
3 Correct 3 ms 15028 KB Output is correct
4 Correct 3 ms 14940 KB Output is correct
5 Correct 3 ms 14936 KB Output is correct
6 Correct 3 ms 14940 KB Output is correct
7 Correct 3 ms 14936 KB Output is correct
8 Correct 3 ms 14940 KB Output is correct
9 Correct 3 ms 14940 KB Output is correct
10 Correct 4 ms 14940 KB Output is correct
11 Correct 3 ms 14936 KB Output is correct
12 Correct 3 ms 14940 KB Output is correct
13 Correct 3 ms 14940 KB Output is correct
14 Correct 3 ms 14940 KB Output is correct
15 Correct 3 ms 14940 KB Output is correct
16 Correct 4 ms 14940 KB Output is correct
17 Correct 3 ms 14940 KB Output is correct
18 Correct 3 ms 14936 KB Output is correct
19 Correct 3 ms 14936 KB Output is correct
20 Correct 3 ms 14940 KB Output is correct
21 Correct 3 ms 14940 KB Output is correct
22 Correct 4 ms 14944 KB Output is correct
23 Correct 5 ms 14936 KB Output is correct
24 Correct 4 ms 14936 KB Output is correct
25 Correct 3 ms 14940 KB Output is correct
26 Correct 4 ms 14940 KB Output is correct
27 Correct 4 ms 14936 KB Output is correct
28 Correct 4 ms 14940 KB Output is correct
29 Correct 4 ms 14940 KB Output is correct
30 Correct 4 ms 14940 KB Output is correct
31 Correct 4 ms 14940 KB Output is correct
32 Correct 4 ms 14940 KB Output is correct
33 Correct 3 ms 14940 KB Output is correct
34 Correct 3 ms 14940 KB Output is correct
35 Correct 4 ms 14940 KB Output is correct
36 Correct 3 ms 15016 KB Output is correct
37 Correct 4 ms 14940 KB Output is correct
38 Correct 3 ms 15016 KB Output is correct
39 Correct 4 ms 14940 KB Output is correct
40 Correct 4 ms 14940 KB Output is correct
41 Correct 3 ms 14936 KB Output is correct
42 Correct 4 ms 14940 KB Output is correct
43 Correct 4 ms 15144 KB Output is correct
44 Correct 4 ms 14940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 14936 KB Output is correct
2 Correct 3 ms 14940 KB Output is correct
3 Correct 3 ms 15028 KB Output is correct
4 Correct 3 ms 14940 KB Output is correct
5 Correct 3 ms 14936 KB Output is correct
6 Correct 3 ms 14940 KB Output is correct
7 Correct 3 ms 14936 KB Output is correct
8 Correct 3 ms 14940 KB Output is correct
9 Correct 3 ms 14940 KB Output is correct
10 Correct 4 ms 14940 KB Output is correct
11 Correct 3 ms 14936 KB Output is correct
12 Correct 3 ms 14940 KB Output is correct
13 Correct 3 ms 14940 KB Output is correct
14 Correct 3 ms 14940 KB Output is correct
15 Correct 3 ms 14940 KB Output is correct
16 Correct 4 ms 14940 KB Output is correct
17 Correct 3 ms 14940 KB Output is correct
18 Correct 3 ms 14936 KB Output is correct
19 Correct 3 ms 14936 KB Output is correct
20 Correct 3 ms 14940 KB Output is correct
21 Correct 3 ms 14940 KB Output is correct
22 Correct 4 ms 14944 KB Output is correct
23 Correct 5 ms 14936 KB Output is correct
24 Correct 4 ms 14936 KB Output is correct
25 Correct 3 ms 14940 KB Output is correct
26 Correct 4 ms 14940 KB Output is correct
27 Correct 4 ms 14936 KB Output is correct
28 Correct 4 ms 14940 KB Output is correct
29 Correct 4 ms 14940 KB Output is correct
30 Correct 4 ms 14940 KB Output is correct
31 Correct 4 ms 14940 KB Output is correct
32 Correct 4 ms 14940 KB Output is correct
33 Correct 3 ms 14940 KB Output is correct
34 Correct 3 ms 14940 KB Output is correct
35 Correct 4 ms 14940 KB Output is correct
36 Correct 3 ms 15016 KB Output is correct
37 Correct 4 ms 14940 KB Output is correct
38 Correct 3 ms 15016 KB Output is correct
39 Correct 4 ms 14940 KB Output is correct
40 Correct 4 ms 14940 KB Output is correct
41 Correct 3 ms 14936 KB Output is correct
42 Correct 4 ms 14940 KB Output is correct
43 Correct 4 ms 15144 KB Output is correct
44 Correct 4 ms 14940 KB Output is correct
45 Correct 144 ms 30800 KB Output is correct
46 Correct 158 ms 30548 KB Output is correct
47 Correct 133 ms 30804 KB Output is correct
48 Correct 124 ms 30664 KB Output is correct
49 Correct 125 ms 30464 KB Output is correct
50 Correct 138 ms 30456 KB Output is correct
51 Correct 124 ms 30800 KB Output is correct
52 Correct 122 ms 30912 KB Output is correct
53 Correct 129 ms 30540 KB Output is correct
54 Correct 107 ms 32760 KB Output is correct
55 Correct 111 ms 32976 KB Output is correct
56 Correct 103 ms 32340 KB Output is correct
57 Correct 112 ms 32588 KB Output is correct
58 Correct 83 ms 28240 KB Output is correct
59 Correct 91 ms 28388 KB Output is correct
60 Correct 82 ms 30772 KB Output is correct
61 Correct 94 ms 27192 KB Output is correct
62 Correct 111 ms 30268 KB Output is correct
63 Correct 80 ms 27444 KB Output is correct
64 Correct 70 ms 27328 KB Output is correct
65 Correct 109 ms 30288 KB Output is correct
66 Correct 72 ms 26660 KB Output is correct