답안 #790436

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
790436 2023-07-22T16:22:06 Z Username4132 Vinjete (COI22_vinjete) C++14
100 / 100
245 ms 93804 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[2*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 2 ms 2772 KB Output is correct
2 Correct 2 ms 2772 KB Output is correct
3 Correct 2 ms 2900 KB Output is correct
4 Correct 2 ms 2900 KB Output is correct
5 Correct 2 ms 3156 KB Output is correct
6 Correct 2 ms 3156 KB Output is correct
7 Correct 1 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 2772 KB Output is correct
11 Correct 2 ms 2900 KB Output is correct
12 Correct 2 ms 2936 KB Output is correct
13 Correct 3 ms 3028 KB Output is correct
14 Correct 2 ms 3028 KB Output is correct
15 Correct 1 ms 2644 KB Output is correct
16 Correct 1 ms 2644 KB Output is correct
17 Correct 2 ms 2900 KB Output is correct
18 Correct 2 ms 2900 KB Output is correct
19 Correct 2 ms 2900 KB Output is correct
20 Correct 2 ms 2900 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 1 ms 2644 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2772 KB Output is correct
2 Correct 2 ms 2772 KB Output is correct
3 Correct 2 ms 2900 KB Output is correct
4 Correct 2 ms 2900 KB Output is correct
5 Correct 2 ms 3156 KB Output is correct
6 Correct 2 ms 3156 KB Output is correct
7 Correct 1 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 2772 KB Output is correct
11 Correct 2 ms 2900 KB Output is correct
12 Correct 2 ms 2936 KB Output is correct
13 Correct 3 ms 3028 KB Output is correct
14 Correct 2 ms 3028 KB Output is correct
15 Correct 1 ms 2644 KB Output is correct
16 Correct 1 ms 2644 KB Output is correct
17 Correct 2 ms 2900 KB Output is correct
18 Correct 2 ms 2900 KB Output is correct
19 Correct 2 ms 2900 KB Output is correct
20 Correct 2 ms 2900 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 1 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 3 ms 3096 KB Output is correct
28 Correct 3 ms 3028 KB Output is correct
29 Correct 2 ms 3284 KB Output is correct
30 Correct 2 ms 3284 KB Output is correct
31 Correct 2 ms 3284 KB Output is correct
32 Correct 3 ms 3208 KB Output is correct
33 Correct 2 ms 3284 KB Output is correct
34 Correct 2 ms 3284 KB Output is correct
35 Correct 2 ms 2816 KB Output is correct
36 Correct 2 ms 2772 KB Output is correct
37 Correct 2 ms 3028 KB Output is correct
38 Correct 2 ms 3028 KB Output is correct
39 Correct 4 ms 3156 KB Output is correct
40 Correct 3 ms 3156 KB Output is correct
41 Correct 2 ms 3156 KB Output is correct
42 Correct 2 ms 3156 KB Output is correct
43 Correct 2 ms 2900 KB Output is correct
44 Correct 2 ms 2900 KB Output is correct
45 Correct 2 ms 3156 KB Output is correct
46 Correct 2 ms 3028 KB Output is correct
47 Correct 3 ms 3156 KB Output is correct
48 Correct 3 ms 3156 KB Output is correct
49 Correct 2 ms 3156 KB Output is correct
50 Correct 2 ms 3156 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2772 KB Output is correct
2 Correct 2 ms 2772 KB Output is correct
3 Correct 2 ms 2900 KB Output is correct
4 Correct 2 ms 2900 KB Output is correct
5 Correct 2 ms 3156 KB Output is correct
6 Correct 2 ms 3156 KB Output is correct
7 Correct 1 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 2772 KB Output is correct
11 Correct 2 ms 2900 KB Output is correct
12 Correct 2 ms 2936 KB Output is correct
13 Correct 3 ms 3028 KB Output is correct
14 Correct 2 ms 3028 KB Output is correct
15 Correct 1 ms 2644 KB Output is correct
16 Correct 1 ms 2644 KB Output is correct
17 Correct 2 ms 2900 KB Output is correct
18 Correct 2 ms 2900 KB Output is correct
19 Correct 2 ms 2900 KB Output is correct
20 Correct 2 ms 2900 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 1 ms 2644 KB Output is correct
25 Correct 27 ms 9420 KB Output is correct
26 Correct 27 ms 9556 KB Output is correct
27 Correct 40 ms 13940 KB Output is correct
28 Correct 42 ms 16368 KB Output is correct
29 Correct 75 ms 31592 KB Output is correct
30 Correct 62 ms 31488 KB Output is correct
31 Correct 7 ms 6264 KB Output is correct
32 Correct 7 ms 6228 KB Output is correct
33 Correct 7 ms 6228 KB Output is correct
34 Correct 7 ms 6228 KB Output is correct
35 Correct 28 ms 6464 KB Output is correct
36 Correct 27 ms 6512 KB Output is correct
37 Correct 46 ms 14396 KB Output is correct
38 Correct 48 ms 14576 KB Output is correct
39 Correct 65 ms 27984 KB Output is correct
40 Correct 67 ms 27860 KB Output is correct
41 Correct 7 ms 5752 KB Output is correct
42 Correct 7 ms 5844 KB Output is correct
43 Correct 33 ms 9412 KB Output is correct
44 Correct 37 ms 13724 KB Output is correct
45 Correct 48 ms 16520 KB Output is correct
46 Correct 45 ms 15248 KB Output is correct
47 Correct 65 ms 27680 KB Output is correct
48 Correct 63 ms 27520 KB Output is correct
49 Correct 8 ms 5712 KB Output is correct
50 Correct 7 ms 5636 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2772 KB Output is correct
2 Correct 2 ms 2772 KB Output is correct
3 Correct 2 ms 2900 KB Output is correct
4 Correct 2 ms 2900 KB Output is correct
5 Correct 2 ms 3156 KB Output is correct
6 Correct 2 ms 3156 KB Output is correct
7 Correct 1 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 2772 KB Output is correct
11 Correct 2 ms 2900 KB Output is correct
12 Correct 2 ms 2936 KB Output is correct
13 Correct 3 ms 3028 KB Output is correct
14 Correct 2 ms 3028 KB Output is correct
15 Correct 1 ms 2644 KB Output is correct
16 Correct 1 ms 2644 KB Output is correct
17 Correct 2 ms 2900 KB Output is correct
18 Correct 2 ms 2900 KB Output is correct
19 Correct 2 ms 2900 KB Output is correct
20 Correct 2 ms 2900 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 1 ms 2644 KB Output is correct
25 Correct 27 ms 9420 KB Output is correct
26 Correct 27 ms 9556 KB Output is correct
27 Correct 40 ms 13940 KB Output is correct
28 Correct 42 ms 16368 KB Output is correct
29 Correct 75 ms 31592 KB Output is correct
30 Correct 62 ms 31488 KB Output is correct
31 Correct 7 ms 6264 KB Output is correct
32 Correct 7 ms 6228 KB Output is correct
33 Correct 7 ms 6228 KB Output is correct
34 Correct 7 ms 6228 KB Output is correct
35 Correct 28 ms 6464 KB Output is correct
36 Correct 27 ms 6512 KB Output is correct
37 Correct 46 ms 14396 KB Output is correct
38 Correct 48 ms 14576 KB Output is correct
39 Correct 65 ms 27984 KB Output is correct
40 Correct 67 ms 27860 KB Output is correct
41 Correct 7 ms 5752 KB Output is correct
42 Correct 7 ms 5844 KB Output is correct
43 Correct 33 ms 9412 KB Output is correct
44 Correct 37 ms 13724 KB Output is correct
45 Correct 48 ms 16520 KB Output is correct
46 Correct 45 ms 15248 KB Output is correct
47 Correct 65 ms 27680 KB Output is correct
48 Correct 63 ms 27520 KB Output is correct
49 Correct 8 ms 5712 KB Output is correct
50 Correct 7 ms 5636 KB Output is correct
51 Correct 66 ms 19816 KB Output is correct
52 Correct 68 ms 19244 KB Output is correct
53 Correct 104 ms 35692 KB Output is correct
54 Correct 109 ms 37408 KB Output is correct
55 Correct 190 ms 79316 KB Output is correct
56 Correct 195 ms 79344 KB Output is correct
57 Correct 26 ms 17928 KB Output is correct
58 Correct 27 ms 17920 KB Output is correct
59 Correct 27 ms 17996 KB Output is correct
60 Correct 27 ms 17944 KB Output is correct
61 Correct 68 ms 12576 KB Output is correct
62 Correct 70 ms 13260 KB Output is correct
63 Correct 131 ms 32288 KB Output is correct
64 Correct 124 ms 31548 KB Output is correct
65 Correct 202 ms 70612 KB Output is correct
66 Correct 187 ms 70288 KB Output is correct
67 Correct 28 ms 16208 KB Output is correct
68 Correct 27 ms 16160 KB Output is correct
69 Correct 95 ms 20844 KB Output is correct
70 Correct 103 ms 29376 KB Output is correct
71 Correct 141 ms 39448 KB Output is correct
72 Correct 157 ms 43964 KB Output is correct
73 Correct 185 ms 69144 KB Output is correct
74 Correct 182 ms 69168 KB Output is correct
75 Correct 29 ms 15976 KB Output is correct
76 Correct 31 ms 15952 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2772 KB Output is correct
2 Correct 2 ms 2772 KB Output is correct
3 Correct 2 ms 2900 KB Output is correct
4 Correct 2 ms 2900 KB Output is correct
5 Correct 2 ms 3156 KB Output is correct
6 Correct 2 ms 3156 KB Output is correct
7 Correct 1 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 2772 KB Output is correct
11 Correct 2 ms 2900 KB Output is correct
12 Correct 2 ms 2936 KB Output is correct
13 Correct 3 ms 3028 KB Output is correct
14 Correct 2 ms 3028 KB Output is correct
15 Correct 1 ms 2644 KB Output is correct
16 Correct 1 ms 2644 KB Output is correct
17 Correct 2 ms 2900 KB Output is correct
18 Correct 2 ms 2900 KB Output is correct
19 Correct 2 ms 2900 KB Output is correct
20 Correct 2 ms 2900 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 1 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 3 ms 3096 KB Output is correct
28 Correct 3 ms 3028 KB Output is correct
29 Correct 2 ms 3284 KB Output is correct
30 Correct 2 ms 3284 KB Output is correct
31 Correct 2 ms 3284 KB Output is correct
32 Correct 3 ms 3208 KB Output is correct
33 Correct 2 ms 3284 KB Output is correct
34 Correct 2 ms 3284 KB Output is correct
35 Correct 2 ms 2816 KB Output is correct
36 Correct 2 ms 2772 KB Output is correct
37 Correct 2 ms 3028 KB Output is correct
38 Correct 2 ms 3028 KB Output is correct
39 Correct 4 ms 3156 KB Output is correct
40 Correct 3 ms 3156 KB Output is correct
41 Correct 2 ms 3156 KB Output is correct
42 Correct 2 ms 3156 KB Output is correct
43 Correct 2 ms 2900 KB Output is correct
44 Correct 2 ms 2900 KB Output is correct
45 Correct 2 ms 3156 KB Output is correct
46 Correct 2 ms 3028 KB Output is correct
47 Correct 3 ms 3156 KB Output is correct
48 Correct 3 ms 3156 KB Output is correct
49 Correct 2 ms 3156 KB Output is correct
50 Correct 2 ms 3156 KB Output is correct
51 Correct 27 ms 9420 KB Output is correct
52 Correct 27 ms 9556 KB Output is correct
53 Correct 40 ms 13940 KB Output is correct
54 Correct 42 ms 16368 KB Output is correct
55 Correct 75 ms 31592 KB Output is correct
56 Correct 62 ms 31488 KB Output is correct
57 Correct 7 ms 6264 KB Output is correct
58 Correct 7 ms 6228 KB Output is correct
59 Correct 7 ms 6228 KB Output is correct
60 Correct 7 ms 6228 KB Output is correct
61 Correct 28 ms 6464 KB Output is correct
62 Correct 27 ms 6512 KB Output is correct
63 Correct 46 ms 14396 KB Output is correct
64 Correct 48 ms 14576 KB Output is correct
65 Correct 65 ms 27984 KB Output is correct
66 Correct 67 ms 27860 KB Output is correct
67 Correct 7 ms 5752 KB Output is correct
68 Correct 7 ms 5844 KB Output is correct
69 Correct 33 ms 9412 KB Output is correct
70 Correct 37 ms 13724 KB Output is correct
71 Correct 48 ms 16520 KB Output is correct
72 Correct 45 ms 15248 KB Output is correct
73 Correct 65 ms 27680 KB Output is correct
74 Correct 63 ms 27520 KB Output is correct
75 Correct 8 ms 5712 KB Output is correct
76 Correct 7 ms 5636 KB Output is correct
77 Correct 66 ms 19816 KB Output is correct
78 Correct 68 ms 19244 KB Output is correct
79 Correct 104 ms 35692 KB Output is correct
80 Correct 109 ms 37408 KB Output is correct
81 Correct 190 ms 79316 KB Output is correct
82 Correct 195 ms 79344 KB Output is correct
83 Correct 26 ms 17928 KB Output is correct
84 Correct 27 ms 17920 KB Output is correct
85 Correct 27 ms 17996 KB Output is correct
86 Correct 27 ms 17944 KB Output is correct
87 Correct 68 ms 12576 KB Output is correct
88 Correct 70 ms 13260 KB Output is correct
89 Correct 131 ms 32288 KB Output is correct
90 Correct 124 ms 31548 KB Output is correct
91 Correct 202 ms 70612 KB Output is correct
92 Correct 187 ms 70288 KB Output is correct
93 Correct 28 ms 16208 KB Output is correct
94 Correct 27 ms 16160 KB Output is correct
95 Correct 95 ms 20844 KB Output is correct
96 Correct 103 ms 29376 KB Output is correct
97 Correct 141 ms 39448 KB Output is correct
98 Correct 157 ms 43964 KB Output is correct
99 Correct 185 ms 69144 KB Output is correct
100 Correct 182 ms 69168 KB Output is correct
101 Correct 29 ms 15976 KB Output is correct
102 Correct 31 ms 15952 KB Output is correct
103 Correct 70 ms 19772 KB Output is correct
104 Correct 67 ms 19556 KB Output is correct
105 Correct 119 ms 47400 KB Output is correct
106 Correct 115 ms 45920 KB Output is correct
107 Correct 225 ms 93804 KB Output is correct
108 Correct 214 ms 93760 KB Output is correct
109 Correct 29 ms 19392 KB Output is correct
110 Correct 29 ms 19396 KB Output is correct
111 Correct 30 ms 19476 KB Output is correct
112 Correct 29 ms 19360 KB Output is correct
113 Correct 74 ms 16800 KB Output is correct
114 Correct 78 ms 16316 KB Output is correct
115 Correct 130 ms 37764 KB Output is correct
116 Correct 141 ms 42668 KB Output is correct
117 Correct 230 ms 84968 KB Output is correct
118 Correct 232 ms 84704 KB Output is correct
119 Correct 29 ms 17736 KB Output is correct
120 Correct 30 ms 17648 KB Output is correct
121 Correct 107 ms 33400 KB Output is correct
122 Correct 106 ms 32856 KB Output is correct
123 Correct 168 ms 46924 KB Output is correct
124 Correct 147 ms 43092 KB Output is correct
125 Correct 245 ms 83600 KB Output is correct
126 Correct 221 ms 83584 KB Output is correct
127 Correct 35 ms 17376 KB Output is correct
128 Correct 38 ms 17460 KB Output is correct