Submission #230053

# Submission time Handle Problem Language Result Execution time Memory
230053 2020-05-07T23:02:53 Z anonymous Constellation 3 (JOI20_constellation3) C++14
14 / 100
1500 ms 10112 KB
#include <iostream>
#include <vector>
#include <set>
#include <utility>
#include <algorithm>
#define MAXN 200005
#define LL long long
#define fi first
#define se second
using namespace std;
int N, M, A[MAXN], X[MAXN], Y[MAXN], C[MAXN];
int Start[MAXN], End[MAXN], Par[MAXN], Order[MAXN];
LL dp[MAXN], Ans;
vector <pair<int,int> > B, Star[MAXN]; //buildings
vector <int> adj[MAXN];
set<pair<int,int> > Active, S;

class fenwick {
    LL BIT[MAXN];
    void add(int p, LL x) {
        for (; p<=N+3; p+=p&(-p)) {BIT[p]+=x;}
    }
    LL PrefSum(int p) {
        LL res = 0;
        for (; p>0; p-=p&(-p)) {res+=BIT[p];}
        return(res);
    }
public:
    void upd(int l, int r, LL x) {
        add(l, x);
        add(r+1, -x);
    }
    LL ask(int p) {return(PrefSum(p));} //point query
} FT;

LL slv(int u) { //cost to resolve the tree
    dp[u] = C[u];
    for (int v: adj[u]) {dp[u] += slv(v);}
    LL res2 = 0;
    /*dp[u] = min(dp[u], FT.ask(X[u]));
    if (Par[u]) {
        FT.upd(Start[u], End[u], C[u]);
        FT.upd(Start[Par[u]], Start[u]-1, dp[u]);
        FT.upd(End[u]+1, End[Par[u]], dp[u]);
    }*/
    for (int i=1; i<=M; i++) {
        if (i == u || Start[i] > End[u] || Start[u] > End[i]) {continue;} //non intersect
        int cur = u, isfa = 0;
        while (cur != 0) {
                if (cur == i) {isfa=1;
                break;}
                cur = Par[cur];
        }
        if (isfa) {continue;}
        if (Start[i] <= X[u] && End[i] >= X[u]) {res2 += C[i];}
        else if (Par[i] && Start[Par[i]] <= X[u] && End[Par[i]] >= X[u]) {res2 += dp[i];}
    }
    dp[u] = min(dp[u], res2);
    return(dp[u]);
}

int main() {
    //freopen("star3in.txt","r",stdin);
    scanf("%d",&N);
    for (int i=1; i<=N; i++) {
        scanf("%d",&A[i]);
    }
    A[N+1] = 1 << 30;
    B.push_back({2e9,  0});
    scanf("%d",&M);
    for (int i=1; i<=M; i++) {
        scanf("%d %d %d",&X[i],&Y[i],&C[i]);
        Star[X[i]].push_back({Y[i],i});
    }

    //find intervals
    for (int i=1; i<=N+1; i++) {
        while (B.size()&& B.back().fi <= A[i]) {B.pop_back();}
        B.push_back({A[i],i});
        for (auto s: Star[i]) {
            int lo = -1, hi = B.size();
            while (lo + 1 != hi) {
                int mid = (lo + hi) >> 1;
                if (B[mid].fi >= s.fi) {lo = mid;}
                else {hi = mid;}
            }
            Start[s.se] = B[lo].se + 1;
            Active.insert(s);
        }
        for (auto p = Active.begin(); p != Active.end(); ) {
            auto P = *p;
            if (P.fi > A[i]) {break;}
            End[P.se] = i-1;
            p = Active.erase(p);
        }
    }

    //build MIS on tree
    for (int i=1; i<=M; i++) {
        Order[i] = i;
    }
    sort(Order+1, Order+M+1, [](int a, int b) {return(End[a] - Start[a] < End[b] - Start[b]);});
    for (int i=1; i<=M; i++) { //bugged
        auto pt = S.lower_bound({Start[Order[i]],-1});
        while (pt != S.end() && (*pt).fi <= End[Order[i]]) {
            Par[(*pt).se] = Order[i];
            adj[Order[i]].push_back((*pt).se);
            pt = S.erase(pt);
        }
        S.insert({Start[Order[i]], Order[i]});
    }

    //dp
    for (int i=1; i<=M; i++) {
        if (!Par[i]) {Ans += slv(i);}
    }
    printf("%lld", Ans);
}

Compilation message

constellation3.cpp: In function 'int main()':
constellation3.cpp:64:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",&N);
     ~~~~~^~~~~~~~~
constellation3.cpp:66:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d",&A[i]);
         ~~~~~^~~~~~~~~~~~
constellation3.cpp:70:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",&M);
     ~~~~~^~~~~~~~~
constellation3.cpp:72:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d %d",&X[i],&Y[i],&C[i]);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 10 ms 9728 KB Output is correct
2 Correct 11 ms 9856 KB Output is correct
3 Correct 10 ms 9856 KB Output is correct
4 Correct 10 ms 9856 KB Output is correct
5 Correct 10 ms 9856 KB Output is correct
6 Correct 11 ms 9856 KB Output is correct
7 Correct 10 ms 9856 KB Output is correct
8 Correct 10 ms 9856 KB Output is correct
9 Correct 10 ms 9856 KB Output is correct
10 Correct 26 ms 9856 KB Output is correct
11 Correct 24 ms 9856 KB Output is correct
12 Correct 27 ms 9856 KB Output is correct
13 Correct 27 ms 9856 KB Output is correct
14 Correct 25 ms 9856 KB Output is correct
15 Correct 23 ms 9856 KB Output is correct
16 Correct 31 ms 9856 KB Output is correct
17 Correct 18 ms 9856 KB Output is correct
18 Correct 26 ms 9856 KB Output is correct
19 Correct 16 ms 9856 KB Output is correct
20 Correct 15 ms 9856 KB Output is correct
21 Correct 30 ms 9856 KB Output is correct
22 Correct 20 ms 9856 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 9728 KB Output is correct
2 Correct 11 ms 9856 KB Output is correct
3 Correct 10 ms 9856 KB Output is correct
4 Correct 10 ms 9856 KB Output is correct
5 Correct 10 ms 9856 KB Output is correct
6 Correct 11 ms 9856 KB Output is correct
7 Correct 10 ms 9856 KB Output is correct
8 Correct 10 ms 9856 KB Output is correct
9 Correct 10 ms 9856 KB Output is correct
10 Correct 26 ms 9856 KB Output is correct
11 Correct 24 ms 9856 KB Output is correct
12 Correct 27 ms 9856 KB Output is correct
13 Correct 27 ms 9856 KB Output is correct
14 Correct 25 ms 9856 KB Output is correct
15 Correct 23 ms 9856 KB Output is correct
16 Correct 31 ms 9856 KB Output is correct
17 Correct 18 ms 9856 KB Output is correct
18 Correct 26 ms 9856 KB Output is correct
19 Correct 16 ms 9856 KB Output is correct
20 Correct 15 ms 9856 KB Output is correct
21 Correct 30 ms 9856 KB Output is correct
22 Correct 20 ms 9856 KB Output is correct
23 Correct 36 ms 10036 KB Output is correct
24 Correct 49 ms 9984 KB Output is correct
25 Correct 37 ms 9984 KB Output is correct
26 Correct 34 ms 10044 KB Output is correct
27 Correct 45 ms 9984 KB Output is correct
28 Correct 33 ms 10112 KB Output is correct
29 Correct 31 ms 9984 KB Output is correct
30 Correct 40 ms 9984 KB Output is correct
31 Correct 32 ms 9984 KB Output is correct
32 Execution timed out 1594 ms 10112 KB Time limit exceeded
33 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 10 ms 9728 KB Output is correct
2 Correct 11 ms 9856 KB Output is correct
3 Correct 10 ms 9856 KB Output is correct
4 Correct 10 ms 9856 KB Output is correct
5 Correct 10 ms 9856 KB Output is correct
6 Correct 11 ms 9856 KB Output is correct
7 Correct 10 ms 9856 KB Output is correct
8 Correct 10 ms 9856 KB Output is correct
9 Correct 10 ms 9856 KB Output is correct
10 Correct 26 ms 9856 KB Output is correct
11 Correct 24 ms 9856 KB Output is correct
12 Correct 27 ms 9856 KB Output is correct
13 Correct 27 ms 9856 KB Output is correct
14 Correct 25 ms 9856 KB Output is correct
15 Correct 23 ms 9856 KB Output is correct
16 Correct 31 ms 9856 KB Output is correct
17 Correct 18 ms 9856 KB Output is correct
18 Correct 26 ms 9856 KB Output is correct
19 Correct 16 ms 9856 KB Output is correct
20 Correct 15 ms 9856 KB Output is correct
21 Correct 30 ms 9856 KB Output is correct
22 Correct 20 ms 9856 KB Output is correct
23 Correct 36 ms 10036 KB Output is correct
24 Correct 49 ms 9984 KB Output is correct
25 Correct 37 ms 9984 KB Output is correct
26 Correct 34 ms 10044 KB Output is correct
27 Correct 45 ms 9984 KB Output is correct
28 Correct 33 ms 10112 KB Output is correct
29 Correct 31 ms 9984 KB Output is correct
30 Correct 40 ms 9984 KB Output is correct
31 Correct 32 ms 9984 KB Output is correct
32 Execution timed out 1594 ms 10112 KB Time limit exceeded
33 Halted 0 ms 0 KB -