Submission #1028310

# Submission time Handle Problem Language Result Execution time Memory
1028310 2024-07-19T16:28:35 Z DennisTran Constellation 3 (JOI20_constellation3) C++17
100 / 100
288 ms 74320 KB
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FOD(i, a, b) for (int i = (a); i >= (b); i--)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define ALL(x) (x).begin(), (x).end()
#define __Dennis_Tran___ signed main()
#define TIME  (1.0 * clock() / CLOCKS_PER_SEC)
#define file(name)  if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); }
 
using namespace std;
 
const int maxN = 2e5 + 5;
 
int n, a[maxN];
int p[20][maxN];
int tin[maxN], tout[maxN], timer;
long long dp[maxN];
vector <int> ke[maxN];
vector <pair <int, int>> stars[maxN];
 
struct rmq{
    int f[20][maxN];
    int Max(int x, int y) {return a[x] >= a[y] ? x : y;}
    int get(int l, int r) {
        int k = __lg(r - l + 1);
        return Max(f[k][l], f[k][r - (1 << k) + 1]);
    }
    void build() {
        FOR(i, 1, n) f[0][i] = i;
        for (int i = 1; (1 << i) <= n; i++)
            for (int j = 1; j <= n - (1 << i) + 1; j++)
                f[i][j] = Max(f[i - 1][j], f[i - 1][j + (1 << i - 1)]);
 
    }
} RMQ;
 
int build_Tree(int l, int r, int parent = 0) {
    if (l > r) return 0;
    int mid = RMQ.get(l, r);
    tin[mid] = ++timer;
    ke[parent].emplace_back(mid);
    p[0][mid] = parent;
    FOR(i, 1, 18) p[i][mid] = p[i - 1][p[i - 1][mid]];
    build_Tree(l, mid - 1, mid);
    build_Tree(mid + 1, r, mid);
    tout[mid] = timer;
    return mid;
}
 
struct BIT{
    long long bit[maxN];
    void update(int x, long long val) {
        for (; x <= n; x += x&-x) bit[x] += val;
    }
    void update(int l, int r, long long val) {
        update(l, val);
        update(r + 1, - val);
    }
 
    long long get(int x) {
        long long ans = 0;
        for (; x; x -= x&-x) ans += bit[x];
        return ans;
    }
} tree1, tree2;
 
void DFS(int u) {
    for (int v : ke[u]) {
        DFS(v);
        dp[u] += dp[v];
    }
 
    tree1.update(tin[u], tout[u], dp[u]); 
    for (auto x : stars[u]) {
        dp[u] = max(dp[u], x.second + tree1.get(tin[x.first]) - tree2.get(tin[x.first]));
    }
    tree2.update(tin[u], tout[u], dp[u]);
}
 
__Dennis_Tran___{
    ios_base::sync_with_stdio(false); 
    cin.tie(nullptr); 
    cout.tie(nullptr);
 
    cin >> n;
    FOR(i, 1, n) cin >> a[i];
    a[n + 1] = n; ++n;
 
    RMQ.build();
    int root = build_Tree(1, n);
 
    long long Total = 0;
    int m; cin >> m; while (m--) {
        int x, y, c; cin >> x >> y >> c;
        int cnode = x; Total += c;
        FOD(i, 18, 0) if (p[i][cnode] && a[p[i][cnode]] < y)
            cnode = p[i][cnode];
        stars[cnode].emplace_back(x, c);
    }
 
    DFS(root);
    cout << Total - dp[root];
    cerr << "Time elapsed: " << TIME << " s.\n";
    return (0 ^ 0);
}

Compilation message

constellation3.cpp: In member function 'void rmq::build()':
constellation3.cpp:32:65: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
   32 |                 f[i][j] = Max(f[i - 1][j], f[i - 1][j + (1 << i - 1)]);
      |                                                               ~~^~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 10072 KB Output is correct
2 Correct 4 ms 10076 KB Output is correct
3 Correct 4 ms 10076 KB Output is correct
4 Correct 4 ms 10076 KB Output is correct
5 Correct 4 ms 10076 KB Output is correct
6 Correct 4 ms 10076 KB Output is correct
7 Correct 5 ms 10076 KB Output is correct
8 Correct 6 ms 10072 KB Output is correct
9 Correct 5 ms 10084 KB Output is correct
10 Correct 5 ms 10076 KB Output is correct
11 Correct 4 ms 10076 KB Output is correct
12 Correct 5 ms 10076 KB Output is correct
13 Correct 4 ms 10076 KB Output is correct
14 Correct 4 ms 10076 KB Output is correct
15 Correct 4 ms 9964 KB Output is correct
16 Correct 4 ms 10076 KB Output is correct
17 Correct 5 ms 10076 KB Output is correct
18 Correct 5 ms 10076 KB Output is correct
19 Correct 5 ms 10076 KB Output is correct
20 Correct 5 ms 10072 KB Output is correct
21 Correct 5 ms 10072 KB Output is correct
22 Correct 5 ms 10044 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 10072 KB Output is correct
2 Correct 4 ms 10076 KB Output is correct
3 Correct 4 ms 10076 KB Output is correct
4 Correct 4 ms 10076 KB Output is correct
5 Correct 4 ms 10076 KB Output is correct
6 Correct 4 ms 10076 KB Output is correct
7 Correct 5 ms 10076 KB Output is correct
8 Correct 6 ms 10072 KB Output is correct
9 Correct 5 ms 10084 KB Output is correct
10 Correct 5 ms 10076 KB Output is correct
11 Correct 4 ms 10076 KB Output is correct
12 Correct 5 ms 10076 KB Output is correct
13 Correct 4 ms 10076 KB Output is correct
14 Correct 4 ms 10076 KB Output is correct
15 Correct 4 ms 9964 KB Output is correct
16 Correct 4 ms 10076 KB Output is correct
17 Correct 5 ms 10076 KB Output is correct
18 Correct 5 ms 10076 KB Output is correct
19 Correct 5 ms 10076 KB Output is correct
20 Correct 5 ms 10072 KB Output is correct
21 Correct 5 ms 10072 KB Output is correct
22 Correct 5 ms 10044 KB Output is correct
23 Correct 6 ms 10332 KB Output is correct
24 Correct 5 ms 10332 KB Output is correct
25 Correct 6 ms 10440 KB Output is correct
26 Correct 6 ms 10584 KB Output is correct
27 Correct 5 ms 10412 KB Output is correct
28 Correct 5 ms 10332 KB Output is correct
29 Correct 5 ms 10332 KB Output is correct
30 Correct 5 ms 10332 KB Output is correct
31 Correct 6 ms 10328 KB Output is correct
32 Correct 6 ms 10332 KB Output is correct
33 Correct 6 ms 10332 KB Output is correct
34 Correct 6 ms 10332 KB Output is correct
35 Correct 6 ms 10332 KB Output is correct
36 Correct 5 ms 10388 KB Output is correct
37 Correct 6 ms 10332 KB Output is correct
38 Correct 6 ms 10588 KB Output is correct
39 Correct 5 ms 10388 KB Output is correct
40 Correct 5 ms 10588 KB Output is correct
41 Correct 7 ms 10332 KB Output is correct
42 Correct 6 ms 10332 KB Output is correct
43 Correct 7 ms 10588 KB Output is correct
44 Correct 6 ms 10332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 10072 KB Output is correct
2 Correct 4 ms 10076 KB Output is correct
3 Correct 4 ms 10076 KB Output is correct
4 Correct 4 ms 10076 KB Output is correct
5 Correct 4 ms 10076 KB Output is correct
6 Correct 4 ms 10076 KB Output is correct
7 Correct 5 ms 10076 KB Output is correct
8 Correct 6 ms 10072 KB Output is correct
9 Correct 5 ms 10084 KB Output is correct
10 Correct 5 ms 10076 KB Output is correct
11 Correct 4 ms 10076 KB Output is correct
12 Correct 5 ms 10076 KB Output is correct
13 Correct 4 ms 10076 KB Output is correct
14 Correct 4 ms 10076 KB Output is correct
15 Correct 4 ms 9964 KB Output is correct
16 Correct 4 ms 10076 KB Output is correct
17 Correct 5 ms 10076 KB Output is correct
18 Correct 5 ms 10076 KB Output is correct
19 Correct 5 ms 10076 KB Output is correct
20 Correct 5 ms 10072 KB Output is correct
21 Correct 5 ms 10072 KB Output is correct
22 Correct 5 ms 10044 KB Output is correct
23 Correct 6 ms 10332 KB Output is correct
24 Correct 5 ms 10332 KB Output is correct
25 Correct 6 ms 10440 KB Output is correct
26 Correct 6 ms 10584 KB Output is correct
27 Correct 5 ms 10412 KB Output is correct
28 Correct 5 ms 10332 KB Output is correct
29 Correct 5 ms 10332 KB Output is correct
30 Correct 5 ms 10332 KB Output is correct
31 Correct 6 ms 10328 KB Output is correct
32 Correct 6 ms 10332 KB Output is correct
33 Correct 6 ms 10332 KB Output is correct
34 Correct 6 ms 10332 KB Output is correct
35 Correct 6 ms 10332 KB Output is correct
36 Correct 5 ms 10388 KB Output is correct
37 Correct 6 ms 10332 KB Output is correct
38 Correct 6 ms 10588 KB Output is correct
39 Correct 5 ms 10388 KB Output is correct
40 Correct 5 ms 10588 KB Output is correct
41 Correct 7 ms 10332 KB Output is correct
42 Correct 6 ms 10332 KB Output is correct
43 Correct 7 ms 10588 KB Output is correct
44 Correct 6 ms 10332 KB Output is correct
45 Correct 195 ms 57964 KB Output is correct
46 Correct 186 ms 57512 KB Output is correct
47 Correct 177 ms 56908 KB Output is correct
48 Correct 184 ms 57680 KB Output is correct
49 Correct 205 ms 56400 KB Output is correct
50 Correct 167 ms 56368 KB Output is correct
51 Correct 167 ms 56416 KB Output is correct
52 Correct 174 ms 57684 KB Output is correct
53 Correct 199 ms 57652 KB Output is correct
54 Correct 288 ms 68176 KB Output is correct
55 Correct 249 ms 64080 KB Output is correct
56 Correct 259 ms 62032 KB Output is correct
57 Correct 256 ms 60628 KB Output is correct
58 Correct 213 ms 64592 KB Output is correct
59 Correct 219 ms 64192 KB Output is correct
60 Correct 120 ms 74320 KB Output is correct
61 Correct 183 ms 57096 KB Output is correct
62 Correct 256 ms 69548 KB Output is correct
63 Correct 150 ms 56220 KB Output is correct
64 Correct 150 ms 55564 KB Output is correct
65 Correct 258 ms 70228 KB Output is correct
66 Correct 202 ms 55860 KB Output is correct