Submission #752174

# Submission time Handle Problem Language Result Execution time Memory
752174 2023-06-02T12:30:54 Z puppy Constellation 3 (JOI20_constellation3) C++17
100 / 100
362 ms 78644 KB
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <functional>
#define int long long
using namespace std;
int N, M;
int X[200005], Y[200005], L[200005], R[200005], A[200005];
long long C[200005];
vector<int> star[200005];
const int inf = 1e9;
struct Line
{
    int s, e;
    int X;
    long long c;
    bool operator<(const Line &ln)
    {
        if (s != ln.s) return s < ln.s;
        else return e > ln.e;
    }
};
Line ln[200005];
int par[200005];
vector<int> g[200005];
int indeg[200005];
long long dp[200005], sum[200005];
vector<int> ts;
int s[200005], e[200005], last[200005];
vector<int> llist[200005];
struct FenWick
{
    vector<long long> tree;
    int n;
    FenWick(int _n){n = _n; tree.resize(n+1);}
    void upd(int id, long long x)
    {
        for (;id<=n;id+=id&-id) tree[id] += x;
    }
    long long query(int id)
    {
        long long ans = 0;
        for (;id;id-=id&-id) ans += tree[id];
        return ans;
    }
};
signed main()
{
    ios::sync_with_stdio(false); cin.tie(0);
    cin >> N;
    for (int i = 1; i <= N; i++) cin >> A[i];
    cin >> M;
    for (int i = 1; i <= M; i++) {
        cin >> X[i] >> Y[i] >> C[i];
        star[X[i]].push_back(i);
    }
    priority_queue<pair<int, int>> pq;
    A[0] = A[N+1] = inf;
    for (int i = 1; i <= N + 1; i++) {
        while (!pq.empty() && -pq.top().first <= A[i]) {
            R[pq.top().second] = i;
            pq.pop();
        }
        for (int k:star[i]) pq.push(make_pair(-Y[k], k));
    }
    for (int i = N; i >= 0; i--) {
        while (!pq.empty() && -pq.top().first <= A[i]) {
            L[pq.top().second] = i;
            pq.pop();
        }
        for (int k:star[i]) pq.push(make_pair(-Y[k], k));
    }
    for (int i = 1; i <= M; i++) ln[i] = {L[i] + 1, R[i] - 1, X[i], C[i]};
    sort(ln + 1, ln + M + 1);
    for (int i = 1; i <= M; i++) llist[ln[i].s].push_back(i);
    priority_queue<int> pq2;
    for (int i = 1; i <= N; i++) {
        for (int k:llist[i]) pq2.push(k);
        while (!pq2.empty() && ln[pq2.top()].e < i) pq2.pop();
        if (!pq2.empty()) last[i] = pq2.top();
    }
    while (!pq2.empty()) pq2.pop();
    for (int i = 1; i <= M; i++) {
        while (!pq2.empty() && ln[pq2.top()].e < ln[i].s) pq2.pop();
        if (!pq2.empty()) {
            par[i] = pq2.top();
            g[par[i]].push_back(i);
        }
        pq2.push(i);
    }
    vector<int> root;
    for (int i = 1; i <= M; i++) {
        if (!par[i]) root.push_back(i);
    }
    int cur = 0;
    vector<int> ts;
    function<void(int)> dfs = [&](int v)
    {
        cur = v;
        s[v] = v;
        for (int i:g[v]) dfs(i);
        e[v] = cur;
        ts.push_back(v);
    };
    for (int i:root) dfs(i);
    FenWick fen(M);
    for (int i:ts) {
        int exc = last[ln[i].X];
        long long tmp1 = 0, tmp2 = 0;
        for (int j:g[i]) tmp1 += dp[j];
        for (int j:g[i]) {
            fen.upd(s[j], tmp1 - dp[j]);
            fen.upd(e[j] + 1, dp[j] - tmp1);
        }
        fen.upd(i, tmp1);
        fen.upd(i+1, -tmp1);
        tmp2 = ln[i].c + fen.query(exc);
        dp[i] = max(tmp1, tmp2);
    }
    long long ans = 0;
    for (int i = 1; i <= M; i++) ans += ln[i].c;
    for (int i:root) ans -= dp[i];
    cout << ans << '\n';
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 10 ms 14548 KB Output is correct
2 Correct 10 ms 14548 KB Output is correct
3 Correct 9 ms 14548 KB Output is correct
4 Correct 8 ms 14548 KB Output is correct
5 Correct 8 ms 14460 KB Output is correct
6 Correct 8 ms 14484 KB Output is correct
7 Correct 10 ms 14548 KB Output is correct
8 Correct 8 ms 14572 KB Output is correct
9 Correct 9 ms 14452 KB Output is correct
10 Correct 8 ms 14548 KB Output is correct
11 Correct 11 ms 14480 KB Output is correct
12 Correct 8 ms 14548 KB Output is correct
13 Correct 8 ms 14548 KB Output is correct
14 Correct 7 ms 14548 KB Output is correct
15 Correct 9 ms 14548 KB Output is correct
16 Correct 8 ms 14484 KB Output is correct
17 Correct 8 ms 14580 KB Output is correct
18 Correct 8 ms 14548 KB Output is correct
19 Correct 8 ms 14548 KB Output is correct
20 Correct 8 ms 14464 KB Output is correct
21 Correct 8 ms 14624 KB Output is correct
22 Correct 8 ms 14592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 14548 KB Output is correct
2 Correct 10 ms 14548 KB Output is correct
3 Correct 9 ms 14548 KB Output is correct
4 Correct 8 ms 14548 KB Output is correct
5 Correct 8 ms 14460 KB Output is correct
6 Correct 8 ms 14484 KB Output is correct
7 Correct 10 ms 14548 KB Output is correct
8 Correct 8 ms 14572 KB Output is correct
9 Correct 9 ms 14452 KB Output is correct
10 Correct 8 ms 14548 KB Output is correct
11 Correct 11 ms 14480 KB Output is correct
12 Correct 8 ms 14548 KB Output is correct
13 Correct 8 ms 14548 KB Output is correct
14 Correct 7 ms 14548 KB Output is correct
15 Correct 9 ms 14548 KB Output is correct
16 Correct 8 ms 14484 KB Output is correct
17 Correct 8 ms 14580 KB Output is correct
18 Correct 8 ms 14548 KB Output is correct
19 Correct 8 ms 14548 KB Output is correct
20 Correct 8 ms 14464 KB Output is correct
21 Correct 8 ms 14624 KB Output is correct
22 Correct 8 ms 14592 KB Output is correct
23 Correct 9 ms 14916 KB Output is correct
24 Correct 9 ms 14932 KB Output is correct
25 Correct 10 ms 14828 KB Output is correct
26 Correct 11 ms 14932 KB Output is correct
27 Correct 11 ms 14928 KB Output is correct
28 Correct 9 ms 14932 KB Output is correct
29 Correct 10 ms 14856 KB Output is correct
30 Correct 9 ms 14856 KB Output is correct
31 Correct 9 ms 14932 KB Output is correct
32 Correct 11 ms 15028 KB Output is correct
33 Correct 10 ms 15116 KB Output is correct
34 Correct 9 ms 15060 KB Output is correct
35 Correct 14 ms 15112 KB Output is correct
36 Correct 10 ms 15040 KB Output is correct
37 Correct 10 ms 15060 KB Output is correct
38 Correct 10 ms 15028 KB Output is correct
39 Correct 10 ms 14932 KB Output is correct
40 Correct 10 ms 15060 KB Output is correct
41 Correct 11 ms 14984 KB Output is correct
42 Correct 10 ms 14932 KB Output is correct
43 Correct 11 ms 15116 KB Output is correct
44 Correct 10 ms 14932 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 14548 KB Output is correct
2 Correct 10 ms 14548 KB Output is correct
3 Correct 9 ms 14548 KB Output is correct
4 Correct 8 ms 14548 KB Output is correct
5 Correct 8 ms 14460 KB Output is correct
6 Correct 8 ms 14484 KB Output is correct
7 Correct 10 ms 14548 KB Output is correct
8 Correct 8 ms 14572 KB Output is correct
9 Correct 9 ms 14452 KB Output is correct
10 Correct 8 ms 14548 KB Output is correct
11 Correct 11 ms 14480 KB Output is correct
12 Correct 8 ms 14548 KB Output is correct
13 Correct 8 ms 14548 KB Output is correct
14 Correct 7 ms 14548 KB Output is correct
15 Correct 9 ms 14548 KB Output is correct
16 Correct 8 ms 14484 KB Output is correct
17 Correct 8 ms 14580 KB Output is correct
18 Correct 8 ms 14548 KB Output is correct
19 Correct 8 ms 14548 KB Output is correct
20 Correct 8 ms 14464 KB Output is correct
21 Correct 8 ms 14624 KB Output is correct
22 Correct 8 ms 14592 KB Output is correct
23 Correct 9 ms 14916 KB Output is correct
24 Correct 9 ms 14932 KB Output is correct
25 Correct 10 ms 14828 KB Output is correct
26 Correct 11 ms 14932 KB Output is correct
27 Correct 11 ms 14928 KB Output is correct
28 Correct 9 ms 14932 KB Output is correct
29 Correct 10 ms 14856 KB Output is correct
30 Correct 9 ms 14856 KB Output is correct
31 Correct 9 ms 14932 KB Output is correct
32 Correct 11 ms 15028 KB Output is correct
33 Correct 10 ms 15116 KB Output is correct
34 Correct 9 ms 15060 KB Output is correct
35 Correct 14 ms 15112 KB Output is correct
36 Correct 10 ms 15040 KB Output is correct
37 Correct 10 ms 15060 KB Output is correct
38 Correct 10 ms 15028 KB Output is correct
39 Correct 10 ms 14932 KB Output is correct
40 Correct 10 ms 15060 KB Output is correct
41 Correct 11 ms 14984 KB Output is correct
42 Correct 10 ms 14932 KB Output is correct
43 Correct 11 ms 15116 KB Output is correct
44 Correct 10 ms 14932 KB Output is correct
45 Correct 267 ms 58512 KB Output is correct
46 Correct 268 ms 57532 KB Output is correct
47 Correct 285 ms 59172 KB Output is correct
48 Correct 289 ms 57440 KB Output is correct
49 Correct 267 ms 57892 KB Output is correct
50 Correct 242 ms 57240 KB Output is correct
51 Correct 293 ms 58220 KB Output is correct
52 Correct 254 ms 58836 KB Output is correct
53 Correct 283 ms 57612 KB Output is correct
54 Correct 344 ms 78644 KB Output is correct
55 Correct 330 ms 78600 KB Output is correct
56 Correct 318 ms 77628 KB Output is correct
57 Correct 287 ms 77868 KB Output is correct
58 Correct 334 ms 76240 KB Output is correct
59 Correct 280 ms 76724 KB Output is correct
60 Correct 199 ms 76664 KB Output is correct
61 Correct 259 ms 61272 KB Output is correct
62 Correct 298 ms 78312 KB Output is correct
63 Correct 290 ms 62176 KB Output is correct
64 Correct 362 ms 59836 KB Output is correct
65 Correct 285 ms 76604 KB Output is correct
66 Correct 299 ms 63936 KB Output is correct