답안 #790433

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
790433 2023-07-22T16:16:46 Z Username4132 Vinjete (COI22_vinjete) C++14
69 / 100
198 ms 81664 KB
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
#define forn(i, n) for(int i=0; i<(int)n; ++i)
#define forsn(i, s, n) for(int i=s; i<(int)n; ++i)
#define PB push_back
#define F first
#define S second

struct Vertex{
    int fsum, tsum;
    Vertex *l, *r;
    Vertex(int _fsum, int _tsum) : fsum(_fsum), tsum(_tsum), l(NULL), r(NULL) {}
    Vertex(Vertex* _l, Vertex* _r) : fsum(_l->fsum + _r->fsum), tsum(_l->tsum + _r->tsum), l(_l), r(_r) {}
};

const int MAXN = 100010;
int n, m, dummy, arr[MAXN];
Vertex* roots[MAXN];
vector<int> els;
vector<pair<int, pair<int, int>>> g[MAXN];

Vertex* build(int tl, int tr){
    if(tl == tr) return new Vertex(arr[tl], 0);
    int tm = (tl + tr)/2;
    return new Vertex(build(tl, tm), build(tm+1, tr));
}

Vertex* update(Vertex* v, int l, int r, int tl, int tr){
    if(v==NULL || l>r) return v;
    if(l==tl && r==tr) return new Vertex(v->fsum, v->fsum);
    int tm = (tl + tr)/2;
    if(v->l == NULL && v->r == NULL) return v;
    return new Vertex(update(v->l, l, min(r, tm), tl, tm), update(v->r, max(l, tm+1), r, tm+1, tr));
}

void dfs(int v, int p){
    for(auto to:g[v]) if(to.F!=p){
        int l = lower_bound(els.begin(), els.end(), to.S.F) - els.begin();
        int r = lower_bound(els.begin(), els.end(), to.S.S) - els.begin() - 1;
        roots[to.F] = update(roots[v], l, r, 0, m-2);
        dfs(to.F, v);
    }
}

int main(){
    scanf("%d %d", &n, &dummy);
    forn(i, n-1){
        int a, b, l, r; scanf("%d %d %d %d", &a, &b, &l, &r); --a, --b, --l;
        g[a].PB({b, {l, r}});
        g[b].PB({a, {l, r}});
        els.PB(l), els.PB(r);
    }
    sort(els.begin(), els.end());
    els.erase(unique(els.begin(), els.end()), els.end());
    m = els.size();
    forn(i, m-1) arr[i]=els[i+1]-els[i];
    roots[0] = build(0, m-2);
    dfs(0, 0);
    forsn(i, 1, n) printf("%d\n", roots[i]->tsum);
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:48:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   48 |     scanf("%d %d", &n, &dummy);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~
Main.cpp:50:30: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   50 |         int a, b, l, r; scanf("%d %d %d %d", &a, &b, &l, &r); --a, --b, --l;
      |                         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 2772 KB Output is correct
2 Correct 3 ms 2796 KB Output is correct
3 Correct 3 ms 2900 KB Output is correct
4 Correct 2 ms 2924 KB Output is correct
5 Correct 2 ms 3156 KB Output is correct
6 Correct 3 ms 3156 KB Output is correct
7 Correct 2 ms 2644 KB Output is correct
8 Correct 1 ms 2644 KB Output is correct
9 Correct 2 ms 2900 KB Output is correct
10 Correct 2 ms 2900 KB Output is correct
11 Correct 2 ms 2900 KB Output is correct
12 Correct 2 ms 2900 KB Output is correct
13 Correct 3 ms 3028 KB Output is correct
14 Correct 3 ms 3056 KB Output is correct
15 Correct 2 ms 2656 KB Output is correct
16 Correct 2 ms 2644 KB Output is correct
17 Correct 2 ms 2916 KB Output is correct
18 Correct 2 ms 2964 KB Output is correct
19 Correct 2 ms 2900 KB Output is correct
20 Correct 3 ms 2916 KB Output is correct
21 Correct 2 ms 3028 KB Output is correct
22 Correct 2 ms 3028 KB Output is correct
23 Correct 1 ms 2644 KB Output is correct
24 Correct 2 ms 2644 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 2772 KB Output is correct
2 Correct 3 ms 2796 KB Output is correct
3 Correct 3 ms 2900 KB Output is correct
4 Correct 2 ms 2924 KB Output is correct
5 Correct 2 ms 3156 KB Output is correct
6 Correct 3 ms 3156 KB Output is correct
7 Correct 2 ms 2644 KB Output is correct
8 Correct 1 ms 2644 KB Output is correct
9 Correct 2 ms 2900 KB Output is correct
10 Correct 2 ms 2900 KB Output is correct
11 Correct 2 ms 2900 KB Output is correct
12 Correct 2 ms 2900 KB Output is correct
13 Correct 3 ms 3028 KB Output is correct
14 Correct 3 ms 3056 KB Output is correct
15 Correct 2 ms 2656 KB Output is correct
16 Correct 2 ms 2644 KB Output is correct
17 Correct 2 ms 2916 KB Output is correct
18 Correct 2 ms 2964 KB Output is correct
19 Correct 2 ms 2900 KB Output is correct
20 Correct 3 ms 2916 KB Output is correct
21 Correct 2 ms 3028 KB Output is correct
22 Correct 2 ms 3028 KB Output is correct
23 Correct 1 ms 2644 KB Output is correct
24 Correct 2 ms 2644 KB Output is correct
25 Correct 2 ms 2900 KB Output is correct
26 Correct 2 ms 2772 KB Output is correct
27 Correct 2 ms 3028 KB Output is correct
28 Correct 2 ms 3056 KB Output is correct
29 Correct 2 ms 3284 KB Output is correct
30 Correct 3 ms 3284 KB Output is correct
31 Correct 2 ms 3284 KB Output is correct
32 Correct 2 ms 3304 KB Output is correct
33 Correct 2 ms 3308 KB Output is correct
34 Correct 3 ms 3284 KB Output is correct
35 Correct 2 ms 2772 KB Output is correct
36 Correct 2 ms 2772 KB Output is correct
37 Correct 3 ms 3028 KB Output is correct
38 Correct 3 ms 3028 KB Output is correct
39 Correct 3 ms 3184 KB Output is correct
40 Correct 2 ms 3176 KB Output is correct
41 Correct 2 ms 3180 KB Output is correct
42 Correct 2 ms 3156 KB Output is correct
43 Correct 3 ms 2920 KB Output is correct
44 Correct 2 ms 2900 KB Output is correct
45 Correct 3 ms 3156 KB Output is correct
46 Correct 3 ms 3048 KB Output is correct
47 Correct 3 ms 3176 KB Output is correct
48 Correct 3 ms 3156 KB Output is correct
49 Correct 3 ms 3156 KB Output is correct
50 Correct 3 ms 3156 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 2772 KB Output is correct
2 Correct 3 ms 2796 KB Output is correct
3 Correct 3 ms 2900 KB Output is correct
4 Correct 2 ms 2924 KB Output is correct
5 Correct 2 ms 3156 KB Output is correct
6 Correct 3 ms 3156 KB Output is correct
7 Correct 2 ms 2644 KB Output is correct
8 Correct 1 ms 2644 KB Output is correct
9 Correct 2 ms 2900 KB Output is correct
10 Correct 2 ms 2900 KB Output is correct
11 Correct 2 ms 2900 KB Output is correct
12 Correct 2 ms 2900 KB Output is correct
13 Correct 3 ms 3028 KB Output is correct
14 Correct 3 ms 3056 KB Output is correct
15 Correct 2 ms 2656 KB Output is correct
16 Correct 2 ms 2644 KB Output is correct
17 Correct 2 ms 2916 KB Output is correct
18 Correct 2 ms 2964 KB Output is correct
19 Correct 2 ms 2900 KB Output is correct
20 Correct 3 ms 2916 KB Output is correct
21 Correct 2 ms 3028 KB Output is correct
22 Correct 2 ms 3028 KB Output is correct
23 Correct 1 ms 2644 KB Output is correct
24 Correct 2 ms 2644 KB Output is correct
25 Correct 27 ms 10276 KB Output is correct
26 Correct 27 ms 10316 KB Output is correct
27 Correct 39 ms 14804 KB Output is correct
28 Correct 48 ms 17272 KB Output is correct
29 Correct 77 ms 32500 KB Output is correct
30 Correct 65 ms 32444 KB Output is correct
31 Correct 7 ms 6372 KB Output is correct
32 Correct 9 ms 6356 KB Output is correct
33 Correct 7 ms 6308 KB Output is correct
34 Correct 7 ms 6256 KB Output is correct
35 Correct 28 ms 7244 KB Output is correct
36 Correct 31 ms 7236 KB Output is correct
37 Correct 48 ms 15136 KB Output is correct
38 Correct 46 ms 15516 KB Output is correct
39 Correct 66 ms 28868 KB Output is correct
40 Correct 69 ms 28688 KB Output is correct
41 Correct 7 ms 5812 KB Output is correct
42 Correct 7 ms 5868 KB Output is correct
43 Correct 42 ms 10192 KB Output is correct
44 Correct 38 ms 14552 KB Output is correct
45 Correct 50 ms 17376 KB Output is correct
46 Correct 45 ms 16212 KB Output is correct
47 Correct 74 ms 28356 KB Output is correct
48 Correct 90 ms 28432 KB Output is correct
49 Correct 7 ms 5868 KB Output is correct
50 Correct 8 ms 5868 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 2772 KB Output is correct
2 Correct 3 ms 2796 KB Output is correct
3 Correct 3 ms 2900 KB Output is correct
4 Correct 2 ms 2924 KB Output is correct
5 Correct 2 ms 3156 KB Output is correct
6 Correct 3 ms 3156 KB Output is correct
7 Correct 2 ms 2644 KB Output is correct
8 Correct 1 ms 2644 KB Output is correct
9 Correct 2 ms 2900 KB Output is correct
10 Correct 2 ms 2900 KB Output is correct
11 Correct 2 ms 2900 KB Output is correct
12 Correct 2 ms 2900 KB Output is correct
13 Correct 3 ms 3028 KB Output is correct
14 Correct 3 ms 3056 KB Output is correct
15 Correct 2 ms 2656 KB Output is correct
16 Correct 2 ms 2644 KB Output is correct
17 Correct 2 ms 2916 KB Output is correct
18 Correct 2 ms 2964 KB Output is correct
19 Correct 2 ms 2900 KB Output is correct
20 Correct 3 ms 2916 KB Output is correct
21 Correct 2 ms 3028 KB Output is correct
22 Correct 2 ms 3028 KB Output is correct
23 Correct 1 ms 2644 KB Output is correct
24 Correct 2 ms 2644 KB Output is correct
25 Correct 27 ms 10276 KB Output is correct
26 Correct 27 ms 10316 KB Output is correct
27 Correct 39 ms 14804 KB Output is correct
28 Correct 48 ms 17272 KB Output is correct
29 Correct 77 ms 32500 KB Output is correct
30 Correct 65 ms 32444 KB Output is correct
31 Correct 7 ms 6372 KB Output is correct
32 Correct 9 ms 6356 KB Output is correct
33 Correct 7 ms 6308 KB Output is correct
34 Correct 7 ms 6256 KB Output is correct
35 Correct 28 ms 7244 KB Output is correct
36 Correct 31 ms 7236 KB Output is correct
37 Correct 48 ms 15136 KB Output is correct
38 Correct 46 ms 15516 KB Output is correct
39 Correct 66 ms 28868 KB Output is correct
40 Correct 69 ms 28688 KB Output is correct
41 Correct 7 ms 5812 KB Output is correct
42 Correct 7 ms 5868 KB Output is correct
43 Correct 42 ms 10192 KB Output is correct
44 Correct 38 ms 14552 KB Output is correct
45 Correct 50 ms 17376 KB Output is correct
46 Correct 45 ms 16212 KB Output is correct
47 Correct 74 ms 28356 KB Output is correct
48 Correct 90 ms 28432 KB Output is correct
49 Correct 7 ms 5868 KB Output is correct
50 Correct 8 ms 5868 KB Output is correct
51 Correct 65 ms 21892 KB Output is correct
52 Correct 65 ms 21180 KB Output is correct
53 Correct 104 ms 38020 KB Output is correct
54 Correct 107 ms 39732 KB Output is correct
55 Correct 192 ms 81576 KB Output is correct
56 Correct 191 ms 81664 KB Output is correct
57 Correct 35 ms 18392 KB Output is correct
58 Correct 27 ms 18380 KB Output is correct
59 Correct 33 ms 18448 KB Output is correct
60 Correct 28 ms 18472 KB Output is correct
61 Correct 69 ms 14604 KB Output is correct
62 Correct 78 ms 15316 KB Output is correct
63 Correct 126 ms 34404 KB Output is correct
64 Correct 126 ms 33888 KB Output is correct
65 Correct 197 ms 72928 KB Output is correct
66 Correct 195 ms 72708 KB Output is correct
67 Correct 29 ms 16568 KB Output is correct
68 Correct 28 ms 16588 KB Output is correct
69 Correct 116 ms 22888 KB Output is correct
70 Correct 106 ms 31424 KB Output is correct
71 Correct 141 ms 41872 KB Output is correct
72 Correct 147 ms 46268 KB Output is correct
73 Correct 183 ms 71484 KB Output is correct
74 Correct 198 ms 71544 KB Output is correct
75 Correct 30 ms 16356 KB Output is correct
76 Correct 31 ms 16424 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 2772 KB Output is correct
2 Correct 3 ms 2796 KB Output is correct
3 Correct 3 ms 2900 KB Output is correct
4 Correct 2 ms 2924 KB Output is correct
5 Correct 2 ms 3156 KB Output is correct
6 Correct 3 ms 3156 KB Output is correct
7 Correct 2 ms 2644 KB Output is correct
8 Correct 1 ms 2644 KB Output is correct
9 Correct 2 ms 2900 KB Output is correct
10 Correct 2 ms 2900 KB Output is correct
11 Correct 2 ms 2900 KB Output is correct
12 Correct 2 ms 2900 KB Output is correct
13 Correct 3 ms 3028 KB Output is correct
14 Correct 3 ms 3056 KB Output is correct
15 Correct 2 ms 2656 KB Output is correct
16 Correct 2 ms 2644 KB Output is correct
17 Correct 2 ms 2916 KB Output is correct
18 Correct 2 ms 2964 KB Output is correct
19 Correct 2 ms 2900 KB Output is correct
20 Correct 3 ms 2916 KB Output is correct
21 Correct 2 ms 3028 KB Output is correct
22 Correct 2 ms 3028 KB Output is correct
23 Correct 1 ms 2644 KB Output is correct
24 Correct 2 ms 2644 KB Output is correct
25 Correct 2 ms 2900 KB Output is correct
26 Correct 2 ms 2772 KB Output is correct
27 Correct 2 ms 3028 KB Output is correct
28 Correct 2 ms 3056 KB Output is correct
29 Correct 2 ms 3284 KB Output is correct
30 Correct 3 ms 3284 KB Output is correct
31 Correct 2 ms 3284 KB Output is correct
32 Correct 2 ms 3304 KB Output is correct
33 Correct 2 ms 3308 KB Output is correct
34 Correct 3 ms 3284 KB Output is correct
35 Correct 2 ms 2772 KB Output is correct
36 Correct 2 ms 2772 KB Output is correct
37 Correct 3 ms 3028 KB Output is correct
38 Correct 3 ms 3028 KB Output is correct
39 Correct 3 ms 3184 KB Output is correct
40 Correct 2 ms 3176 KB Output is correct
41 Correct 2 ms 3180 KB Output is correct
42 Correct 2 ms 3156 KB Output is correct
43 Correct 3 ms 2920 KB Output is correct
44 Correct 2 ms 2900 KB Output is correct
45 Correct 3 ms 3156 KB Output is correct
46 Correct 3 ms 3048 KB Output is correct
47 Correct 3 ms 3176 KB Output is correct
48 Correct 3 ms 3156 KB Output is correct
49 Correct 3 ms 3156 KB Output is correct
50 Correct 3 ms 3156 KB Output is correct
51 Correct 27 ms 10276 KB Output is correct
52 Correct 27 ms 10316 KB Output is correct
53 Correct 39 ms 14804 KB Output is correct
54 Correct 48 ms 17272 KB Output is correct
55 Correct 77 ms 32500 KB Output is correct
56 Correct 65 ms 32444 KB Output is correct
57 Correct 7 ms 6372 KB Output is correct
58 Correct 9 ms 6356 KB Output is correct
59 Correct 7 ms 6308 KB Output is correct
60 Correct 7 ms 6256 KB Output is correct
61 Correct 28 ms 7244 KB Output is correct
62 Correct 31 ms 7236 KB Output is correct
63 Correct 48 ms 15136 KB Output is correct
64 Correct 46 ms 15516 KB Output is correct
65 Correct 66 ms 28868 KB Output is correct
66 Correct 69 ms 28688 KB Output is correct
67 Correct 7 ms 5812 KB Output is correct
68 Correct 7 ms 5868 KB Output is correct
69 Correct 42 ms 10192 KB Output is correct
70 Correct 38 ms 14552 KB Output is correct
71 Correct 50 ms 17376 KB Output is correct
72 Correct 45 ms 16212 KB Output is correct
73 Correct 74 ms 28356 KB Output is correct
74 Correct 90 ms 28432 KB Output is correct
75 Correct 7 ms 5868 KB Output is correct
76 Correct 8 ms 5868 KB Output is correct
77 Correct 65 ms 21892 KB Output is correct
78 Correct 65 ms 21180 KB Output is correct
79 Correct 104 ms 38020 KB Output is correct
80 Correct 107 ms 39732 KB Output is correct
81 Correct 192 ms 81576 KB Output is correct
82 Correct 191 ms 81664 KB Output is correct
83 Correct 35 ms 18392 KB Output is correct
84 Correct 27 ms 18380 KB Output is correct
85 Correct 33 ms 18448 KB Output is correct
86 Correct 28 ms 18472 KB Output is correct
87 Correct 69 ms 14604 KB Output is correct
88 Correct 78 ms 15316 KB Output is correct
89 Correct 126 ms 34404 KB Output is correct
90 Correct 126 ms 33888 KB Output is correct
91 Correct 197 ms 72928 KB Output is correct
92 Correct 195 ms 72708 KB Output is correct
93 Correct 29 ms 16568 KB Output is correct
94 Correct 28 ms 16588 KB Output is correct
95 Correct 116 ms 22888 KB Output is correct
96 Correct 106 ms 31424 KB Output is correct
97 Correct 141 ms 41872 KB Output is correct
98 Correct 147 ms 46268 KB Output is correct
99 Correct 183 ms 71484 KB Output is correct
100 Correct 198 ms 71544 KB Output is correct
101 Correct 30 ms 16356 KB Output is correct
102 Correct 31 ms 16424 KB Output is correct
103 Correct 68 ms 22080 KB Output is correct
104 Correct 68 ms 21872 KB Output is correct
105 Runtime error 59 ms 16976 KB Execution killed with signal 11
106 Halted 0 ms 0 KB -