답안 #748845

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
748845 2023-05-27T05:19:13 Z 반딧불(#9966) Vinjete (COI22_vinjete) C++17
100 / 100
268 ms 32068 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

struct Edge{
    int s, e, l, r;
    Edge(){}
    Edge(int s, int e, int l, int r): s(s), e(e), l(l), r(r){}
};

struct segTree{
    int cnt[2000002], sz[2000002], sum[2000002];

    void init(int i, int l, int r, int *arr){
        cnt[i] = sum[i] = 0;
        if(l==r){
            sz[i] = arr[l];
            return;
        }
        int m = (l+r)>>1;
        init(i*2, l, m, arr);
        init(i*2+1, m+1, r, arr);
        sz[i] = sz[i*2] + sz[i*2+1];
    }

    void update(int i, int l, int r, int s, int e, int v){
        if(r<s || e<l) return;
        if(s<=l && r<=e){
            cnt[i] -= v;
            sum[i] = (cnt[i] ? sz[i] : sum[i*2] + sum[i*2+1]);
            return;
        }
        int m = (l+r)>>1;
        update(i*2, l, m, s, e, v);
        update(i*2+1, m+1, r, s, e, v);
        sum[i] = (cnt[i] ? sz[i] : sum[i*2] + sum[i*2+1]);
    }

    int query(){
        return sum[1];
    }
} tree;

int n, m, k;
int arr[300002];
vector<Edge> link[100002];
vector<int> stp;

int ans[100002];

void dfs(int x, int p){
    ans[x] = tree.query();
    for(Edge e: link[x]){
        if(e.e == p) continue;
        tree.update(1, 1, k, e.l, e.r, 1);
        dfs(e.e, x);
        tree.update(1, 1, k, e.l, e.r, -1);
    }
}

int main(){
    scanf("%d %d", &n, &m);
    stp.push_back(1), stp.push_back(m+1);
    for(int i=1; i<n; i++){
        int x, y, l, r;
        scanf("%d %d %d %d", &x, &y, &l, &r);
        stp.push_back(l), stp.push_back(r+1);
        link[x].push_back(Edge(x, y, l, r));
        link[y].push_back(Edge(y, x, l, r));
    }
    sort(stp.begin(), stp.end());
    stp.erase(unique(stp.begin(), stp.end()), stp.end());
    k = (int)stp.size() - 1;
    for(int i=1; i<=k; i++) arr[i] = stp[i] - stp[i-1];
    for(int i=1; i<=n; i++){
        for(Edge &edge: link[i]){
            edge.l = lower_bound(stp.begin(), stp.end(), edge.l) - stp.begin() + 1;
            edge.r = lower_bound(stp.begin(), stp.end(), edge.r + 1) - stp.begin();
        }
    }
    tree.init(1, 1, k, arr);

    dfs(1, -1);

    for(int i=2; i<=n; i++) printf("%d\n", ans[i]);
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:64:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   64 |     scanf("%d %d", &n, &m);
      |     ~~~~~^~~~~~~~~~~~~~~~~
Main.cpp:68:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   68 |         scanf("%d %d %d %d", &x, &y, &l, &r);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 2772 KB Output is correct
2 Correct 3 ms 2772 KB Output is correct
3 Correct 3 ms 2772 KB Output is correct
4 Correct 3 ms 2900 KB Output is correct
5 Correct 3 ms 2796 KB Output is correct
6 Correct 3 ms 2772 KB Output is correct
7 Correct 2 ms 2644 KB Output is correct
8 Correct 1 ms 2644 KB Output is correct
9 Correct 3 ms 2772 KB Output is correct
10 Correct 3 ms 2772 KB Output is correct
11 Correct 3 ms 2772 KB Output is correct
12 Correct 4 ms 2772 KB Output is correct
13 Correct 3 ms 2688 KB Output is correct
14 Correct 4 ms 2772 KB Output is correct
15 Correct 2 ms 2644 KB Output is correct
16 Correct 2 ms 2644 KB Output is correct
17 Correct 3 ms 2720 KB Output is correct
18 Correct 3 ms 2644 KB Output is correct
19 Correct 4 ms 2772 KB Output is correct
20 Correct 3 ms 2772 KB Output is correct
21 Correct 3 ms 2772 KB Output is correct
22 Correct 3 ms 2664 KB Output is correct
23 Correct 2 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 2772 KB Output is correct
3 Correct 3 ms 2772 KB Output is correct
4 Correct 3 ms 2900 KB Output is correct
5 Correct 3 ms 2796 KB Output is correct
6 Correct 3 ms 2772 KB Output is correct
7 Correct 2 ms 2644 KB Output is correct
8 Correct 1 ms 2644 KB Output is correct
9 Correct 3 ms 2772 KB Output is correct
10 Correct 3 ms 2772 KB Output is correct
11 Correct 3 ms 2772 KB Output is correct
12 Correct 4 ms 2772 KB Output is correct
13 Correct 3 ms 2688 KB Output is correct
14 Correct 4 ms 2772 KB Output is correct
15 Correct 2 ms 2644 KB Output is correct
16 Correct 2 ms 2644 KB Output is correct
17 Correct 3 ms 2720 KB Output is correct
18 Correct 3 ms 2644 KB Output is correct
19 Correct 4 ms 2772 KB Output is correct
20 Correct 3 ms 2772 KB Output is correct
21 Correct 3 ms 2772 KB Output is correct
22 Correct 3 ms 2664 KB Output is correct
23 Correct 2 ms 2644 KB Output is correct
24 Correct 2 ms 2644 KB Output is correct
25 Correct 3 ms 2772 KB Output is correct
26 Correct 3 ms 2824 KB Output is correct
27 Correct 3 ms 2852 KB Output is correct
28 Correct 3 ms 2852 KB Output is correct
29 Correct 3 ms 2920 KB Output is correct
30 Correct 3 ms 2900 KB Output is correct
31 Correct 3 ms 2944 KB Output is correct
32 Correct 3 ms 2900 KB Output is correct
33 Correct 2 ms 2900 KB Output is correct
34 Correct 3 ms 2944 KB Output is correct
35 Correct 3 ms 2700 KB Output is correct
36 Correct 2 ms 2772 KB Output is correct
37 Correct 3 ms 2772 KB Output is correct
38 Correct 3 ms 2728 KB Output is correct
39 Correct 3 ms 2812 KB Output is correct
40 Correct 3 ms 2772 KB Output is correct
41 Correct 3 ms 2772 KB Output is correct
42 Correct 3 ms 2772 KB Output is correct
43 Correct 3 ms 2680 KB Output is correct
44 Correct 3 ms 2704 KB Output is correct
45 Correct 3 ms 2796 KB Output is correct
46 Correct 3 ms 2772 KB Output is correct
47 Correct 3 ms 2772 KB Output is correct
48 Correct 3 ms 2772 KB Output is correct
49 Correct 3 ms 2724 KB Output is correct
50 Correct 3 ms 2772 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 2772 KB Output is correct
2 Correct 3 ms 2772 KB Output is correct
3 Correct 3 ms 2772 KB Output is correct
4 Correct 3 ms 2900 KB Output is correct
5 Correct 3 ms 2796 KB Output is correct
6 Correct 3 ms 2772 KB Output is correct
7 Correct 2 ms 2644 KB Output is correct
8 Correct 1 ms 2644 KB Output is correct
9 Correct 3 ms 2772 KB Output is correct
10 Correct 3 ms 2772 KB Output is correct
11 Correct 3 ms 2772 KB Output is correct
12 Correct 4 ms 2772 KB Output is correct
13 Correct 3 ms 2688 KB Output is correct
14 Correct 4 ms 2772 KB Output is correct
15 Correct 2 ms 2644 KB Output is correct
16 Correct 2 ms 2644 KB Output is correct
17 Correct 3 ms 2720 KB Output is correct
18 Correct 3 ms 2644 KB Output is correct
19 Correct 4 ms 2772 KB Output is correct
20 Correct 3 ms 2772 KB Output is correct
21 Correct 3 ms 2772 KB Output is correct
22 Correct 3 ms 2664 KB Output is correct
23 Correct 2 ms 2644 KB Output is correct
24 Correct 2 ms 2644 KB Output is correct
25 Correct 46 ms 10820 KB Output is correct
26 Correct 43 ms 10856 KB Output is correct
27 Correct 73 ms 11800 KB Output is correct
28 Correct 68 ms 11972 KB Output is correct
29 Correct 57 ms 12756 KB Output is correct
30 Correct 54 ms 12676 KB Output is correct
31 Correct 8 ms 4052 KB Output is correct
32 Correct 6 ms 4052 KB Output is correct
33 Correct 6 ms 4108 KB Output is correct
34 Correct 6 ms 4052 KB Output is correct
35 Correct 44 ms 6440 KB Output is correct
36 Correct 46 ms 6804 KB Output is correct
37 Correct 79 ms 7620 KB Output is correct
38 Correct 74 ms 7660 KB Output is correct
39 Correct 60 ms 7984 KB Output is correct
40 Correct 59 ms 7832 KB Output is correct
41 Correct 7 ms 3540 KB Output is correct
42 Correct 7 ms 3596 KB Output is correct
43 Correct 46 ms 6132 KB Output is correct
44 Correct 46 ms 6028 KB Output is correct
45 Correct 75 ms 7032 KB Output is correct
46 Correct 74 ms 6948 KB Output is correct
47 Correct 66 ms 7828 KB Output is correct
48 Correct 61 ms 7796 KB Output is correct
49 Correct 7 ms 3512 KB Output is correct
50 Correct 7 ms 3600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 2772 KB Output is correct
2 Correct 3 ms 2772 KB Output is correct
3 Correct 3 ms 2772 KB Output is correct
4 Correct 3 ms 2900 KB Output is correct
5 Correct 3 ms 2796 KB Output is correct
6 Correct 3 ms 2772 KB Output is correct
7 Correct 2 ms 2644 KB Output is correct
8 Correct 1 ms 2644 KB Output is correct
9 Correct 3 ms 2772 KB Output is correct
10 Correct 3 ms 2772 KB Output is correct
11 Correct 3 ms 2772 KB Output is correct
12 Correct 4 ms 2772 KB Output is correct
13 Correct 3 ms 2688 KB Output is correct
14 Correct 4 ms 2772 KB Output is correct
15 Correct 2 ms 2644 KB Output is correct
16 Correct 2 ms 2644 KB Output is correct
17 Correct 3 ms 2720 KB Output is correct
18 Correct 3 ms 2644 KB Output is correct
19 Correct 4 ms 2772 KB Output is correct
20 Correct 3 ms 2772 KB Output is correct
21 Correct 3 ms 2772 KB Output is correct
22 Correct 3 ms 2664 KB Output is correct
23 Correct 2 ms 2644 KB Output is correct
24 Correct 2 ms 2644 KB Output is correct
25 Correct 46 ms 10820 KB Output is correct
26 Correct 43 ms 10856 KB Output is correct
27 Correct 73 ms 11800 KB Output is correct
28 Correct 68 ms 11972 KB Output is correct
29 Correct 57 ms 12756 KB Output is correct
30 Correct 54 ms 12676 KB Output is correct
31 Correct 8 ms 4052 KB Output is correct
32 Correct 6 ms 4052 KB Output is correct
33 Correct 6 ms 4108 KB Output is correct
34 Correct 6 ms 4052 KB Output is correct
35 Correct 44 ms 6440 KB Output is correct
36 Correct 46 ms 6804 KB Output is correct
37 Correct 79 ms 7620 KB Output is correct
38 Correct 74 ms 7660 KB Output is correct
39 Correct 60 ms 7984 KB Output is correct
40 Correct 59 ms 7832 KB Output is correct
41 Correct 7 ms 3540 KB Output is correct
42 Correct 7 ms 3596 KB Output is correct
43 Correct 46 ms 6132 KB Output is correct
44 Correct 46 ms 6028 KB Output is correct
45 Correct 75 ms 7032 KB Output is correct
46 Correct 74 ms 6948 KB Output is correct
47 Correct 66 ms 7828 KB Output is correct
48 Correct 61 ms 7796 KB Output is correct
49 Correct 7 ms 3512 KB Output is correct
50 Correct 7 ms 3600 KB Output is correct
51 Correct 102 ms 23704 KB Output is correct
52 Correct 106 ms 23744 KB Output is correct
53 Correct 178 ms 27548 KB Output is correct
54 Correct 181 ms 27284 KB Output is correct
55 Correct 144 ms 26940 KB Output is correct
56 Correct 144 ms 27132 KB Output is correct
57 Correct 22 ms 7724 KB Output is correct
58 Correct 21 ms 7776 KB Output is correct
59 Correct 22 ms 7708 KB Output is correct
60 Correct 22 ms 7760 KB Output is correct
61 Correct 114 ms 12748 KB Output is correct
62 Correct 115 ms 13268 KB Output is correct
63 Correct 212 ms 16404 KB Output is correct
64 Correct 204 ms 16564 KB Output is correct
65 Correct 162 ms 16724 KB Output is correct
66 Correct 165 ms 15676 KB Output is correct
67 Correct 25 ms 5448 KB Output is correct
68 Correct 26 ms 5456 KB Output is correct
69 Correct 129 ms 11624 KB Output is correct
70 Correct 128 ms 11544 KB Output is correct
71 Correct 220 ms 15212 KB Output is correct
72 Correct 226 ms 15280 KB Output is correct
73 Correct 191 ms 15096 KB Output is correct
74 Correct 170 ms 14924 KB Output is correct
75 Correct 27 ms 5316 KB Output is correct
76 Correct 27 ms 5264 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 2772 KB Output is correct
2 Correct 3 ms 2772 KB Output is correct
3 Correct 3 ms 2772 KB Output is correct
4 Correct 3 ms 2900 KB Output is correct
5 Correct 3 ms 2796 KB Output is correct
6 Correct 3 ms 2772 KB Output is correct
7 Correct 2 ms 2644 KB Output is correct
8 Correct 1 ms 2644 KB Output is correct
9 Correct 3 ms 2772 KB Output is correct
10 Correct 3 ms 2772 KB Output is correct
11 Correct 3 ms 2772 KB Output is correct
12 Correct 4 ms 2772 KB Output is correct
13 Correct 3 ms 2688 KB Output is correct
14 Correct 4 ms 2772 KB Output is correct
15 Correct 2 ms 2644 KB Output is correct
16 Correct 2 ms 2644 KB Output is correct
17 Correct 3 ms 2720 KB Output is correct
18 Correct 3 ms 2644 KB Output is correct
19 Correct 4 ms 2772 KB Output is correct
20 Correct 3 ms 2772 KB Output is correct
21 Correct 3 ms 2772 KB Output is correct
22 Correct 3 ms 2664 KB Output is correct
23 Correct 2 ms 2644 KB Output is correct
24 Correct 2 ms 2644 KB Output is correct
25 Correct 3 ms 2772 KB Output is correct
26 Correct 3 ms 2824 KB Output is correct
27 Correct 3 ms 2852 KB Output is correct
28 Correct 3 ms 2852 KB Output is correct
29 Correct 3 ms 2920 KB Output is correct
30 Correct 3 ms 2900 KB Output is correct
31 Correct 3 ms 2944 KB Output is correct
32 Correct 3 ms 2900 KB Output is correct
33 Correct 2 ms 2900 KB Output is correct
34 Correct 3 ms 2944 KB Output is correct
35 Correct 3 ms 2700 KB Output is correct
36 Correct 2 ms 2772 KB Output is correct
37 Correct 3 ms 2772 KB Output is correct
38 Correct 3 ms 2728 KB Output is correct
39 Correct 3 ms 2812 KB Output is correct
40 Correct 3 ms 2772 KB Output is correct
41 Correct 3 ms 2772 KB Output is correct
42 Correct 3 ms 2772 KB Output is correct
43 Correct 3 ms 2680 KB Output is correct
44 Correct 3 ms 2704 KB Output is correct
45 Correct 3 ms 2796 KB Output is correct
46 Correct 3 ms 2772 KB Output is correct
47 Correct 3 ms 2772 KB Output is correct
48 Correct 3 ms 2772 KB Output is correct
49 Correct 3 ms 2724 KB Output is correct
50 Correct 3 ms 2772 KB Output is correct
51 Correct 46 ms 10820 KB Output is correct
52 Correct 43 ms 10856 KB Output is correct
53 Correct 73 ms 11800 KB Output is correct
54 Correct 68 ms 11972 KB Output is correct
55 Correct 57 ms 12756 KB Output is correct
56 Correct 54 ms 12676 KB Output is correct
57 Correct 8 ms 4052 KB Output is correct
58 Correct 6 ms 4052 KB Output is correct
59 Correct 6 ms 4108 KB Output is correct
60 Correct 6 ms 4052 KB Output is correct
61 Correct 44 ms 6440 KB Output is correct
62 Correct 46 ms 6804 KB Output is correct
63 Correct 79 ms 7620 KB Output is correct
64 Correct 74 ms 7660 KB Output is correct
65 Correct 60 ms 7984 KB Output is correct
66 Correct 59 ms 7832 KB Output is correct
67 Correct 7 ms 3540 KB Output is correct
68 Correct 7 ms 3596 KB Output is correct
69 Correct 46 ms 6132 KB Output is correct
70 Correct 46 ms 6028 KB Output is correct
71 Correct 75 ms 7032 KB Output is correct
72 Correct 74 ms 6948 KB Output is correct
73 Correct 66 ms 7828 KB Output is correct
74 Correct 61 ms 7796 KB Output is correct
75 Correct 7 ms 3512 KB Output is correct
76 Correct 7 ms 3600 KB Output is correct
77 Correct 102 ms 23704 KB Output is correct
78 Correct 106 ms 23744 KB Output is correct
79 Correct 178 ms 27548 KB Output is correct
80 Correct 181 ms 27284 KB Output is correct
81 Correct 144 ms 26940 KB Output is correct
82 Correct 144 ms 27132 KB Output is correct
83 Correct 22 ms 7724 KB Output is correct
84 Correct 21 ms 7776 KB Output is correct
85 Correct 22 ms 7708 KB Output is correct
86 Correct 22 ms 7760 KB Output is correct
87 Correct 114 ms 12748 KB Output is correct
88 Correct 115 ms 13268 KB Output is correct
89 Correct 212 ms 16404 KB Output is correct
90 Correct 204 ms 16564 KB Output is correct
91 Correct 162 ms 16724 KB Output is correct
92 Correct 165 ms 15676 KB Output is correct
93 Correct 25 ms 5448 KB Output is correct
94 Correct 26 ms 5456 KB Output is correct
95 Correct 129 ms 11624 KB Output is correct
96 Correct 128 ms 11544 KB Output is correct
97 Correct 220 ms 15212 KB Output is correct
98 Correct 226 ms 15280 KB Output is correct
99 Correct 191 ms 15096 KB Output is correct
100 Correct 170 ms 14924 KB Output is correct
101 Correct 27 ms 5316 KB Output is correct
102 Correct 27 ms 5264 KB Output is correct
103 Correct 114 ms 24576 KB Output is correct
104 Correct 111 ms 24556 KB Output is correct
105 Correct 212 ms 32068 KB Output is correct
106 Correct 219 ms 31324 KB Output is correct
107 Correct 162 ms 31372 KB Output is correct
108 Correct 168 ms 31588 KB Output is correct
109 Correct 24 ms 8820 KB Output is correct
110 Correct 23 ms 8804 KB Output is correct
111 Correct 23 ms 8776 KB Output is correct
112 Correct 23 ms 8800 KB Output is correct
113 Correct 126 ms 14380 KB Output is correct
114 Correct 122 ms 14000 KB Output is correct
115 Correct 260 ms 21528 KB Output is correct
116 Correct 250 ms 21524 KB Output is correct
117 Correct 222 ms 21080 KB Output is correct
118 Correct 204 ms 19980 KB Output is correct
119 Correct 28 ms 6752 KB Output is correct
120 Correct 28 ms 6728 KB Output is correct
121 Correct 137 ms 12392 KB Output is correct
122 Correct 126 ms 12292 KB Output is correct
123 Correct 268 ms 17288 KB Output is correct
124 Correct 262 ms 16828 KB Output is correct
125 Correct 212 ms 16184 KB Output is correct
126 Correct 213 ms 18808 KB Output is correct
127 Correct 31 ms 6344 KB Output is correct
128 Correct 34 ms 6344 KB Output is correct