Submission #1028301

# Submission time Handle Problem Language Result Execution time Memory
1028301 2024-07-19T16:06:05 Z DennisTran Constellation 3 (JOI20_constellation3) C++17
100 / 100
316 ms 74324 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) {
    long long sum = 0;
    for (int v : ke[u]) {
        DFS(v);
        sum += dp[v];
    }

    tree1.update(tin[u], tout[u], sum);
    dp[u] = sum;
    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 10076 KB Output is correct
2 Correct 5 ms 10076 KB Output is correct
3 Correct 4 ms 9872 KB Output is correct
4 Correct 5 ms 9912 KB Output is correct
5 Correct 5 ms 10092 KB Output is correct
6 Correct 4 ms 10076 KB Output is correct
7 Correct 5 ms 10076 KB Output is correct
8 Correct 5 ms 10076 KB Output is correct
9 Correct 5 ms 10088 KB Output is correct
10 Correct 5 ms 9920 KB Output is correct
11 Correct 5 ms 10076 KB Output is correct
12 Correct 5 ms 10060 KB Output is correct
13 Correct 4 ms 10076 KB Output is correct
14 Correct 5 ms 10076 KB Output is correct
15 Correct 4 ms 10076 KB Output is correct
16 Correct 5 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 4 ms 10076 KB Output is correct
21 Correct 5 ms 10076 KB Output is correct
22 Correct 5 ms 10012 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 10076 KB Output is correct
2 Correct 5 ms 10076 KB Output is correct
3 Correct 4 ms 9872 KB Output is correct
4 Correct 5 ms 9912 KB Output is correct
5 Correct 5 ms 10092 KB Output is correct
6 Correct 4 ms 10076 KB Output is correct
7 Correct 5 ms 10076 KB Output is correct
8 Correct 5 ms 10076 KB Output is correct
9 Correct 5 ms 10088 KB Output is correct
10 Correct 5 ms 9920 KB Output is correct
11 Correct 5 ms 10076 KB Output is correct
12 Correct 5 ms 10060 KB Output is correct
13 Correct 4 ms 10076 KB Output is correct
14 Correct 5 ms 10076 KB Output is correct
15 Correct 4 ms 10076 KB Output is correct
16 Correct 5 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 4 ms 10076 KB Output is correct
21 Correct 5 ms 10076 KB Output is correct
22 Correct 5 ms 10012 KB Output is correct
23 Correct 6 ms 10332 KB Output is correct
24 Correct 5 ms 10332 KB Output is correct
25 Correct 7 ms 10332 KB Output is correct
26 Correct 7 ms 10332 KB Output is correct
27 Correct 6 ms 10332 KB Output is correct
28 Correct 6 ms 10400 KB Output is correct
29 Correct 5 ms 10332 KB Output is correct
30 Correct 6 ms 10356 KB Output is correct
31 Correct 7 ms 10332 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 7 ms 10332 KB Output is correct
36 Correct 6 ms 10572 KB Output is correct
37 Correct 6 ms 10332 KB Output is correct
38 Correct 6 ms 10400 KB Output is correct
39 Correct 6 ms 10332 KB Output is correct
40 Correct 5 ms 10588 KB Output is correct
41 Correct 5 ms 10404 KB Output is correct
42 Correct 5 ms 10332 KB Output is correct
43 Correct 8 ms 10588 KB Output is correct
44 Correct 5 ms 10332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 10076 KB Output is correct
2 Correct 5 ms 10076 KB Output is correct
3 Correct 4 ms 9872 KB Output is correct
4 Correct 5 ms 9912 KB Output is correct
5 Correct 5 ms 10092 KB Output is correct
6 Correct 4 ms 10076 KB Output is correct
7 Correct 5 ms 10076 KB Output is correct
8 Correct 5 ms 10076 KB Output is correct
9 Correct 5 ms 10088 KB Output is correct
10 Correct 5 ms 9920 KB Output is correct
11 Correct 5 ms 10076 KB Output is correct
12 Correct 5 ms 10060 KB Output is correct
13 Correct 4 ms 10076 KB Output is correct
14 Correct 5 ms 10076 KB Output is correct
15 Correct 4 ms 10076 KB Output is correct
16 Correct 5 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 4 ms 10076 KB Output is correct
21 Correct 5 ms 10076 KB Output is correct
22 Correct 5 ms 10012 KB Output is correct
23 Correct 6 ms 10332 KB Output is correct
24 Correct 5 ms 10332 KB Output is correct
25 Correct 7 ms 10332 KB Output is correct
26 Correct 7 ms 10332 KB Output is correct
27 Correct 6 ms 10332 KB Output is correct
28 Correct 6 ms 10400 KB Output is correct
29 Correct 5 ms 10332 KB Output is correct
30 Correct 6 ms 10356 KB Output is correct
31 Correct 7 ms 10332 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 7 ms 10332 KB Output is correct
36 Correct 6 ms 10572 KB Output is correct
37 Correct 6 ms 10332 KB Output is correct
38 Correct 6 ms 10400 KB Output is correct
39 Correct 6 ms 10332 KB Output is correct
40 Correct 5 ms 10588 KB Output is correct
41 Correct 5 ms 10404 KB Output is correct
42 Correct 5 ms 10332 KB Output is correct
43 Correct 8 ms 10588 KB Output is correct
44 Correct 5 ms 10332 KB Output is correct
45 Correct 191 ms 57976 KB Output is correct
46 Correct 196 ms 57428 KB Output is correct
47 Correct 170 ms 56792 KB Output is correct
48 Correct 197 ms 57864 KB Output is correct
49 Correct 202 ms 56404 KB Output is correct
50 Correct 184 ms 56412 KB Output is correct
51 Correct 190 ms 56660 KB Output is correct
52 Correct 198 ms 57600 KB Output is correct
53 Correct 187 ms 57428 KB Output is correct
54 Correct 316 ms 68136 KB Output is correct
55 Correct 281 ms 64084 KB Output is correct
56 Correct 264 ms 61880 KB Output is correct
57 Correct 261 ms 60500 KB Output is correct
58 Correct 227 ms 64608 KB Output is correct
59 Correct 213 ms 64340 KB Output is correct
60 Correct 129 ms 74324 KB Output is correct
61 Correct 175 ms 57040 KB Output is correct
62 Correct 282 ms 69460 KB Output is correct
63 Correct 166 ms 56188 KB Output is correct
64 Correct 163 ms 55636 KB Output is correct
65 Correct 308 ms 70228 KB Output is correct
66 Correct 172 ms 55892 KB Output is correct