답안 #230063

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
230063 2020-05-08T00:33:10 Z anonymous 별자리 3 (JOI20_constellation3) C++14
100 / 100
491 ms 45036 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);
    }
    for (int v: adj[u]) {
        FT.upd(Start[v], End[v], C[v]);
        FT.upd(Start[u], Start[v]-1, dp[v]);
        FT.upd(End[v]+1, End[u], dp[v]);
    }
    dp[u] = min(dp[u], FT.ask(X[u]));
    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++) {
        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:52:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",&N);
     ~~~~~^~~~~~~~~
constellation3.cpp:54:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d",&A[i]);
         ~~~~~^~~~~~~~~~~~
constellation3.cpp:58:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",&M);
     ~~~~~^~~~~~~~~
constellation3.cpp:60: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]);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 9856 KB Output is correct
2 Correct 10 ms 9856 KB Output is correct
3 Correct 13 ms 9728 KB Output is correct
4 Correct 12 ms 9856 KB Output is correct
5 Correct 10 ms 9856 KB Output is correct
6 Correct 10 ms 9856 KB Output is correct
7 Correct 10 ms 9856 KB Output is correct
8 Correct 10 ms 9728 KB Output is correct
9 Correct 10 ms 9856 KB Output is correct
10 Correct 10 ms 9856 KB Output is correct
11 Correct 10 ms 9856 KB Output is correct
12 Correct 10 ms 9856 KB Output is correct
13 Correct 11 ms 9856 KB Output is correct
14 Correct 10 ms 9856 KB Output is correct
15 Correct 10 ms 9856 KB Output is correct
16 Correct 11 ms 9856 KB Output is correct
17 Correct 11 ms 9856 KB Output is correct
18 Correct 11 ms 9856 KB Output is correct
19 Correct 10 ms 9856 KB Output is correct
20 Correct 10 ms 9856 KB Output is correct
21 Correct 11 ms 9856 KB Output is correct
22 Correct 10 ms 9856 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 9856 KB Output is correct
2 Correct 10 ms 9856 KB Output is correct
3 Correct 13 ms 9728 KB Output is correct
4 Correct 12 ms 9856 KB Output is correct
5 Correct 10 ms 9856 KB Output is correct
6 Correct 10 ms 9856 KB Output is correct
7 Correct 10 ms 9856 KB Output is correct
8 Correct 10 ms 9728 KB Output is correct
9 Correct 10 ms 9856 KB Output is correct
10 Correct 10 ms 9856 KB Output is correct
11 Correct 10 ms 9856 KB Output is correct
12 Correct 10 ms 9856 KB Output is correct
13 Correct 11 ms 9856 KB Output is correct
14 Correct 10 ms 9856 KB Output is correct
15 Correct 10 ms 9856 KB Output is correct
16 Correct 11 ms 9856 KB Output is correct
17 Correct 11 ms 9856 KB Output is correct
18 Correct 11 ms 9856 KB Output is correct
19 Correct 10 ms 9856 KB Output is correct
20 Correct 10 ms 9856 KB Output is correct
21 Correct 11 ms 9856 KB Output is correct
22 Correct 10 ms 9856 KB Output is correct
23 Correct 12 ms 9984 KB Output is correct
24 Correct 13 ms 10112 KB Output is correct
25 Correct 13 ms 9984 KB Output is correct
26 Correct 14 ms 9984 KB Output is correct
27 Correct 13 ms 9984 KB Output is correct
28 Correct 13 ms 9984 KB Output is correct
29 Correct 12 ms 9984 KB Output is correct
30 Correct 13 ms 10112 KB Output is correct
31 Correct 12 ms 9984 KB Output is correct
32 Correct 12 ms 10112 KB Output is correct
33 Correct 12 ms 10112 KB Output is correct
34 Correct 12 ms 10112 KB Output is correct
35 Correct 14 ms 10112 KB Output is correct
36 Correct 13 ms 10240 KB Output is correct
37 Correct 12 ms 10112 KB Output is correct
38 Correct 12 ms 10112 KB Output is correct
39 Correct 12 ms 9984 KB Output is correct
40 Correct 13 ms 10112 KB Output is correct
41 Correct 12 ms 10112 KB Output is correct
42 Correct 12 ms 9984 KB Output is correct
43 Correct 12 ms 10240 KB Output is correct
44 Correct 12 ms 10112 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 9856 KB Output is correct
2 Correct 10 ms 9856 KB Output is correct
3 Correct 13 ms 9728 KB Output is correct
4 Correct 12 ms 9856 KB Output is correct
5 Correct 10 ms 9856 KB Output is correct
6 Correct 10 ms 9856 KB Output is correct
7 Correct 10 ms 9856 KB Output is correct
8 Correct 10 ms 9728 KB Output is correct
9 Correct 10 ms 9856 KB Output is correct
10 Correct 10 ms 9856 KB Output is correct
11 Correct 10 ms 9856 KB Output is correct
12 Correct 10 ms 9856 KB Output is correct
13 Correct 11 ms 9856 KB Output is correct
14 Correct 10 ms 9856 KB Output is correct
15 Correct 10 ms 9856 KB Output is correct
16 Correct 11 ms 9856 KB Output is correct
17 Correct 11 ms 9856 KB Output is correct
18 Correct 11 ms 9856 KB Output is correct
19 Correct 10 ms 9856 KB Output is correct
20 Correct 10 ms 9856 KB Output is correct
21 Correct 11 ms 9856 KB Output is correct
22 Correct 10 ms 9856 KB Output is correct
23 Correct 12 ms 9984 KB Output is correct
24 Correct 13 ms 10112 KB Output is correct
25 Correct 13 ms 9984 KB Output is correct
26 Correct 14 ms 9984 KB Output is correct
27 Correct 13 ms 9984 KB Output is correct
28 Correct 13 ms 9984 KB Output is correct
29 Correct 12 ms 9984 KB Output is correct
30 Correct 13 ms 10112 KB Output is correct
31 Correct 12 ms 9984 KB Output is correct
32 Correct 12 ms 10112 KB Output is correct
33 Correct 12 ms 10112 KB Output is correct
34 Correct 12 ms 10112 KB Output is correct
35 Correct 14 ms 10112 KB Output is correct
36 Correct 13 ms 10240 KB Output is correct
37 Correct 12 ms 10112 KB Output is correct
38 Correct 12 ms 10112 KB Output is correct
39 Correct 12 ms 9984 KB Output is correct
40 Correct 13 ms 10112 KB Output is correct
41 Correct 12 ms 10112 KB Output is correct
42 Correct 12 ms 9984 KB Output is correct
43 Correct 12 ms 10240 KB Output is correct
44 Correct 12 ms 10112 KB Output is correct
45 Correct 429 ms 34412 KB Output is correct
46 Correct 401 ms 33812 KB Output is correct
47 Correct 417 ms 34676 KB Output is correct
48 Correct 388 ms 33656 KB Output is correct
49 Correct 423 ms 33912 KB Output is correct
50 Correct 390 ms 33784 KB Output is correct
51 Correct 391 ms 34040 KB Output is correct
52 Correct 399 ms 34552 KB Output is correct
53 Correct 396 ms 33956 KB Output is correct
54 Correct 489 ms 45036 KB Output is correct
55 Correct 464 ms 44784 KB Output is correct
56 Correct 454 ms 44268 KB Output is correct
57 Correct 482 ms 44276 KB Output is correct
58 Correct 442 ms 43364 KB Output is correct
59 Correct 427 ms 43768 KB Output is correct
60 Correct 216 ms 41720 KB Output is correct
61 Correct 377 ms 35832 KB Output is correct
62 Correct 491 ms 44592 KB Output is correct
63 Correct 355 ms 36088 KB Output is correct
64 Correct 344 ms 34936 KB Output is correct
65 Correct 437 ms 43836 KB Output is correct
66 Correct 388 ms 36984 KB Output is correct