답안 #761359

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
761359 2023-06-19T14:32:53 Z Dan4Life Vinjete (COI22_vinjete) C++17
69 / 100
925 ms 524288 KB
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
const int mxN = (int)1e5+10;

int n, mx, IND = 1;
int segTree[mxN*300], lazy[mxN*300];
vector<pair<int,pair<int,int>>> adj[mxN];
int ans[mxN], root[mxN], L[mxN*300], R[mxN*300];

int newLeaf(int v){ int p = ++IND; segTree[p]=v; return p; }

int newParent(int l, int r){
	int p = ++IND; L[p]=l, R[p]=r; lazy[p]=-1;
	segTree[p] = segTree[L[p]]+segTree[R[p]];
	return p;
}

int newLazyChild(int p, int v, int l, int r){
	int ind = ++IND;
    L[ind] = L[p];
    R[ind] = R[p];
    lazy[ind] = v;
    segTree[ind] = (r-l+1)*v;
	return ind;
}

void prop(int p, int l, int r){
	if(!p or l==r or lazy[p]==-1) return;
	int mid = (l+r)/2;
    if(!L[p]) L[p]=++IND;
    if(!R[p]) R[p]=++IND;
	L[p] = newLazyChild(L[p],lazy[p],l,mid);
	R[p] = newLazyChild(R[p],lazy[p],mid+1,r);
	lazy[p]=-1;
}

int upd(int i, int j, int v, int p, int l=1, int r=mx){
	if(i>r or j<l or i>j or !p) return p; prop(p,l,r);
	if(i<=l and r<=j) return newLazyChild(p,v,l,r);
	int mid = (l+r)/2;
    if(!L[p] and i<=mid) L[p]=++IND;
    if(!R[p] and j>mid) R[p]=++IND;
	return newParent(upd(i,j,v,L[p],l,mid),upd(i,j,v,R[p],mid+1,r));
}

int query(int i, int j, int p, int l=1, int r=mx){
	if(i>r or j<l or i>j or !p) return 0; prop(p,l,r);
	if(i<=l and r<=j) return segTree[p];
	int mid = (l+r)/2;
	return query(i,j,L[p],l,mid)+query(i,j,R[p],mid+1,r);
}

void dfs(int s, int p){
    ans[s] = segTree[root[s]];
    for(auto x : adj[s]){
        int u = x.fi; if(u==p) continue;
        root[u] = upd(x.se.fi,x.se.se,1,root[s]); dfs(u,s);
    }
}

int32_t main()
{
    ios_base::sync_with_stdio(false); cin.tie(0);
    cin >> n >> mx; root[1] = 1;
    memset(lazy,-1,sizeof(lazy));
    for(int i = 1; i < n; i++){
        int a, b, l, r; cin >> a >> b >> l >> r;
        adj[a].pb({b,mp(l,r)}); adj[b].pb({a,mp(l,r)});
    }
    dfs(1,0);
    for(int i = 2; i <= n; i++) cout << ans[i] << "\n";
}

/*
const int mxN = (int)1e5+10;
int n, m, ans[mxN];
vector<pair<int,pair<int,int>>> adj[mxN];

int segTree[mxN*2];
vector<int> lazy(mxN*2, -1);

void prop(int p, int l, int r){
    if(l==r or lazy[p]==-1) return;
    int mid = (l+r)>>1; int rp = p+2*(mid-l+1);
    lazy[p+1] = lazy[rp] = lazy[p]; lazy[p]=-1;
    segTree[p+1] = (mid-l+1)*lazy[p+1];
    segTree[rp] = (r-mid)*lazy[p+1];
}

void upd(int i, int j, int v, int p=0, int l=1, int r=n){
    if(i>r or j<l or i>j) return; prop(p,l,r);
    if(i<=l and r<=j){
        lazy[p]=v; segTree[p] = (r-l+1)*v;
        return;
    }
    int mid = (l+r)>>1; int rp = p+2*(mid-l+1);
    upd(i,j,v,p+1,l,mid), upd(i,j,v,rp,mid+1,r);
    segTree[p] = segTree[p+1]+segTree[rp];
}

void dfs(int s, int p){
    ans[s] = segTree[0];
    for(auto x : adj[s]){
        int u = x.fi; if(u==p) continue;
        upd(x.se.fi,x.se.se,1); dfs(u,s);
        rollback();
    }
}
*/

Compilation message

Main.cpp: In function 'int upd(int, int, int, int, int, int)':
Main.cpp:42:2: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   42 |  if(i>r or j<l or i>j or !p) return p; prop(p,l,r);
      |  ^~
Main.cpp:42:40: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   42 |  if(i>r or j<l or i>j or !p) return p; prop(p,l,r);
      |                                        ^~~~
Main.cpp: In function 'int query(int, int, int, int, int)':
Main.cpp:51:2: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   51 |  if(i>r or j<l or i>j or !p) return 0; prop(p,l,r);
      |  ^~
Main.cpp:51:40: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   51 |  if(i>r or j<l or i>j or !p) return 0; prop(p,l,r);
      |                                        ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 45 ms 120892 KB Output is correct
2 Correct 45 ms 120924 KB Output is correct
3 Correct 45 ms 120800 KB Output is correct
4 Correct 53 ms 120792 KB Output is correct
5 Correct 45 ms 120304 KB Output is correct
6 Correct 44 ms 120268 KB Output is correct
7 Correct 44 ms 120040 KB Output is correct
8 Correct 44 ms 120044 KB Output is correct
9 Correct 49 ms 120744 KB Output is correct
10 Correct 44 ms 120780 KB Output is correct
11 Correct 52 ms 120756 KB Output is correct
12 Correct 45 ms 120640 KB Output is correct
13 Correct 44 ms 120328 KB Output is correct
14 Correct 44 ms 120272 KB Output is correct
15 Correct 45 ms 120092 KB Output is correct
16 Correct 45 ms 120148 KB Output is correct
17 Correct 45 ms 120788 KB Output is correct
18 Correct 47 ms 120876 KB Output is correct
19 Correct 53 ms 120648 KB Output is correct
20 Correct 45 ms 120596 KB Output is correct
21 Correct 47 ms 120240 KB Output is correct
22 Correct 45 ms 120256 KB Output is correct
23 Correct 44 ms 120080 KB Output is correct
24 Correct 45 ms 120120 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 45 ms 120892 KB Output is correct
2 Correct 45 ms 120924 KB Output is correct
3 Correct 45 ms 120800 KB Output is correct
4 Correct 53 ms 120792 KB Output is correct
5 Correct 45 ms 120304 KB Output is correct
6 Correct 44 ms 120268 KB Output is correct
7 Correct 44 ms 120040 KB Output is correct
8 Correct 44 ms 120044 KB Output is correct
9 Correct 49 ms 120744 KB Output is correct
10 Correct 44 ms 120780 KB Output is correct
11 Correct 52 ms 120756 KB Output is correct
12 Correct 45 ms 120640 KB Output is correct
13 Correct 44 ms 120328 KB Output is correct
14 Correct 44 ms 120272 KB Output is correct
15 Correct 45 ms 120092 KB Output is correct
16 Correct 45 ms 120148 KB Output is correct
17 Correct 45 ms 120788 KB Output is correct
18 Correct 47 ms 120876 KB Output is correct
19 Correct 53 ms 120648 KB Output is correct
20 Correct 45 ms 120596 KB Output is correct
21 Correct 47 ms 120240 KB Output is correct
22 Correct 45 ms 120256 KB Output is correct
23 Correct 44 ms 120080 KB Output is correct
24 Correct 45 ms 120120 KB Output is correct
25 Correct 46 ms 122728 KB Output is correct
26 Correct 47 ms 122768 KB Output is correct
27 Correct 48 ms 124108 KB Output is correct
28 Correct 47 ms 124088 KB Output is correct
29 Correct 45 ms 120760 KB Output is correct
30 Correct 46 ms 120804 KB Output is correct
31 Correct 46 ms 121568 KB Output is correct
32 Correct 46 ms 121648 KB Output is correct
33 Correct 46 ms 121532 KB Output is correct
34 Correct 46 ms 121548 KB Output is correct
35 Correct 46 ms 122316 KB Output is correct
36 Correct 46 ms 122280 KB Output is correct
37 Correct 48 ms 124016 KB Output is correct
38 Correct 48 ms 124096 KB Output is correct
39 Correct 46 ms 120772 KB Output is correct
40 Correct 46 ms 120808 KB Output is correct
41 Correct 49 ms 121548 KB Output is correct
42 Correct 46 ms 121548 KB Output is correct
43 Correct 46 ms 122108 KB Output is correct
44 Correct 45 ms 122072 KB Output is correct
45 Correct 51 ms 123572 KB Output is correct
46 Correct 47 ms 123816 KB Output is correct
47 Correct 45 ms 120780 KB Output is correct
48 Correct 45 ms 120712 KB Output is correct
49 Correct 46 ms 121548 KB Output is correct
50 Correct 47 ms 121548 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 45 ms 120892 KB Output is correct
2 Correct 45 ms 120924 KB Output is correct
3 Correct 45 ms 120800 KB Output is correct
4 Correct 53 ms 120792 KB Output is correct
5 Correct 45 ms 120304 KB Output is correct
6 Correct 44 ms 120268 KB Output is correct
7 Correct 44 ms 120040 KB Output is correct
8 Correct 44 ms 120044 KB Output is correct
9 Correct 49 ms 120744 KB Output is correct
10 Correct 44 ms 120780 KB Output is correct
11 Correct 52 ms 120756 KB Output is correct
12 Correct 45 ms 120640 KB Output is correct
13 Correct 44 ms 120328 KB Output is correct
14 Correct 44 ms 120272 KB Output is correct
15 Correct 45 ms 120092 KB Output is correct
16 Correct 45 ms 120148 KB Output is correct
17 Correct 45 ms 120788 KB Output is correct
18 Correct 47 ms 120876 KB Output is correct
19 Correct 53 ms 120648 KB Output is correct
20 Correct 45 ms 120596 KB Output is correct
21 Correct 47 ms 120240 KB Output is correct
22 Correct 45 ms 120256 KB Output is correct
23 Correct 44 ms 120080 KB Output is correct
24 Correct 45 ms 120120 KB Output is correct
25 Correct 100 ms 172904 KB Output is correct
26 Correct 131 ms 172964 KB Output is correct
27 Correct 106 ms 171332 KB Output is correct
28 Correct 104 ms 171216 KB Output is correct
29 Correct 74 ms 133540 KB Output is correct
30 Correct 84 ms 133556 KB Output is correct
31 Correct 51 ms 122188 KB Output is correct
32 Correct 50 ms 122192 KB Output is correct
33 Correct 53 ms 122176 KB Output is correct
34 Correct 49 ms 122180 KB Output is correct
35 Correct 100 ms 163748 KB Output is correct
36 Correct 102 ms 163812 KB Output is correct
37 Correct 111 ms 169736 KB Output is correct
38 Correct 109 ms 169164 KB Output is correct
39 Correct 77 ms 131620 KB Output is correct
40 Correct 78 ms 131488 KB Output is correct
41 Correct 52 ms 122116 KB Output is correct
42 Correct 51 ms 121972 KB Output is correct
43 Correct 97 ms 160388 KB Output is correct
44 Correct 97 ms 160480 KB Output is correct
45 Correct 111 ms 164276 KB Output is correct
46 Correct 111 ms 163288 KB Output is correct
47 Correct 86 ms 130892 KB Output is correct
48 Correct 88 ms 131256 KB Output is correct
49 Correct 50 ms 122292 KB Output is correct
50 Correct 51 ms 121840 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 45 ms 120892 KB Output is correct
2 Correct 45 ms 120924 KB Output is correct
3 Correct 45 ms 120800 KB Output is correct
4 Correct 53 ms 120792 KB Output is correct
5 Correct 45 ms 120304 KB Output is correct
6 Correct 44 ms 120268 KB Output is correct
7 Correct 44 ms 120040 KB Output is correct
8 Correct 44 ms 120044 KB Output is correct
9 Correct 49 ms 120744 KB Output is correct
10 Correct 44 ms 120780 KB Output is correct
11 Correct 52 ms 120756 KB Output is correct
12 Correct 45 ms 120640 KB Output is correct
13 Correct 44 ms 120328 KB Output is correct
14 Correct 44 ms 120272 KB Output is correct
15 Correct 45 ms 120092 KB Output is correct
16 Correct 45 ms 120148 KB Output is correct
17 Correct 45 ms 120788 KB Output is correct
18 Correct 47 ms 120876 KB Output is correct
19 Correct 53 ms 120648 KB Output is correct
20 Correct 45 ms 120596 KB Output is correct
21 Correct 47 ms 120240 KB Output is correct
22 Correct 45 ms 120256 KB Output is correct
23 Correct 44 ms 120080 KB Output is correct
24 Correct 45 ms 120120 KB Output is correct
25 Correct 100 ms 172904 KB Output is correct
26 Correct 131 ms 172964 KB Output is correct
27 Correct 106 ms 171332 KB Output is correct
28 Correct 104 ms 171216 KB Output is correct
29 Correct 74 ms 133540 KB Output is correct
30 Correct 84 ms 133556 KB Output is correct
31 Correct 51 ms 122188 KB Output is correct
32 Correct 50 ms 122192 KB Output is correct
33 Correct 53 ms 122176 KB Output is correct
34 Correct 49 ms 122180 KB Output is correct
35 Correct 100 ms 163748 KB Output is correct
36 Correct 102 ms 163812 KB Output is correct
37 Correct 111 ms 169736 KB Output is correct
38 Correct 109 ms 169164 KB Output is correct
39 Correct 77 ms 131620 KB Output is correct
40 Correct 78 ms 131488 KB Output is correct
41 Correct 52 ms 122116 KB Output is correct
42 Correct 51 ms 121972 KB Output is correct
43 Correct 97 ms 160388 KB Output is correct
44 Correct 97 ms 160480 KB Output is correct
45 Correct 111 ms 164276 KB Output is correct
46 Correct 111 ms 163288 KB Output is correct
47 Correct 86 ms 130892 KB Output is correct
48 Correct 88 ms 131256 KB Output is correct
49 Correct 50 ms 122292 KB Output is correct
50 Correct 51 ms 121840 KB Output is correct
51 Correct 188 ms 263048 KB Output is correct
52 Correct 190 ms 263060 KB Output is correct
53 Correct 241 ms 261644 KB Output is correct
54 Correct 226 ms 261668 KB Output is correct
55 Correct 138 ms 155372 KB Output is correct
56 Correct 130 ms 155104 KB Output is correct
57 Correct 60 ms 128392 KB Output is correct
58 Correct 61 ms 128436 KB Output is correct
59 Correct 65 ms 128540 KB Output is correct
60 Correct 59 ms 128464 KB Output is correct
61 Correct 216 ms 237808 KB Output is correct
62 Correct 198 ms 237888 KB Output is correct
63 Correct 244 ms 256808 KB Output is correct
64 Correct 245 ms 255892 KB Output is correct
65 Correct 162 ms 151164 KB Output is correct
66 Correct 139 ms 150696 KB Output is correct
67 Correct 60 ms 127600 KB Output is correct
68 Correct 61 ms 127504 KB Output is correct
69 Correct 190 ms 228884 KB Output is correct
70 Correct 197 ms 228984 KB Output is correct
71 Correct 271 ms 245612 KB Output is correct
72 Correct 245 ms 244668 KB Output is correct
73 Correct 156 ms 148964 KB Output is correct
74 Correct 168 ms 148736 KB Output is correct
75 Correct 66 ms 127288 KB Output is correct
76 Correct 63 ms 128140 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 45 ms 120892 KB Output is correct
2 Correct 45 ms 120924 KB Output is correct
3 Correct 45 ms 120800 KB Output is correct
4 Correct 53 ms 120792 KB Output is correct
5 Correct 45 ms 120304 KB Output is correct
6 Correct 44 ms 120268 KB Output is correct
7 Correct 44 ms 120040 KB Output is correct
8 Correct 44 ms 120044 KB Output is correct
9 Correct 49 ms 120744 KB Output is correct
10 Correct 44 ms 120780 KB Output is correct
11 Correct 52 ms 120756 KB Output is correct
12 Correct 45 ms 120640 KB Output is correct
13 Correct 44 ms 120328 KB Output is correct
14 Correct 44 ms 120272 KB Output is correct
15 Correct 45 ms 120092 KB Output is correct
16 Correct 45 ms 120148 KB Output is correct
17 Correct 45 ms 120788 KB Output is correct
18 Correct 47 ms 120876 KB Output is correct
19 Correct 53 ms 120648 KB Output is correct
20 Correct 45 ms 120596 KB Output is correct
21 Correct 47 ms 120240 KB Output is correct
22 Correct 45 ms 120256 KB Output is correct
23 Correct 44 ms 120080 KB Output is correct
24 Correct 45 ms 120120 KB Output is correct
25 Correct 46 ms 122728 KB Output is correct
26 Correct 47 ms 122768 KB Output is correct
27 Correct 48 ms 124108 KB Output is correct
28 Correct 47 ms 124088 KB Output is correct
29 Correct 45 ms 120760 KB Output is correct
30 Correct 46 ms 120804 KB Output is correct
31 Correct 46 ms 121568 KB Output is correct
32 Correct 46 ms 121648 KB Output is correct
33 Correct 46 ms 121532 KB Output is correct
34 Correct 46 ms 121548 KB Output is correct
35 Correct 46 ms 122316 KB Output is correct
36 Correct 46 ms 122280 KB Output is correct
37 Correct 48 ms 124016 KB Output is correct
38 Correct 48 ms 124096 KB Output is correct
39 Correct 46 ms 120772 KB Output is correct
40 Correct 46 ms 120808 KB Output is correct
41 Correct 49 ms 121548 KB Output is correct
42 Correct 46 ms 121548 KB Output is correct
43 Correct 46 ms 122108 KB Output is correct
44 Correct 45 ms 122072 KB Output is correct
45 Correct 51 ms 123572 KB Output is correct
46 Correct 47 ms 123816 KB Output is correct
47 Correct 45 ms 120780 KB Output is correct
48 Correct 45 ms 120712 KB Output is correct
49 Correct 46 ms 121548 KB Output is correct
50 Correct 47 ms 121548 KB Output is correct
51 Correct 100 ms 172904 KB Output is correct
52 Correct 131 ms 172964 KB Output is correct
53 Correct 106 ms 171332 KB Output is correct
54 Correct 104 ms 171216 KB Output is correct
55 Correct 74 ms 133540 KB Output is correct
56 Correct 84 ms 133556 KB Output is correct
57 Correct 51 ms 122188 KB Output is correct
58 Correct 50 ms 122192 KB Output is correct
59 Correct 53 ms 122176 KB Output is correct
60 Correct 49 ms 122180 KB Output is correct
61 Correct 100 ms 163748 KB Output is correct
62 Correct 102 ms 163812 KB Output is correct
63 Correct 111 ms 169736 KB Output is correct
64 Correct 109 ms 169164 KB Output is correct
65 Correct 77 ms 131620 KB Output is correct
66 Correct 78 ms 131488 KB Output is correct
67 Correct 52 ms 122116 KB Output is correct
68 Correct 51 ms 121972 KB Output is correct
69 Correct 97 ms 160388 KB Output is correct
70 Correct 97 ms 160480 KB Output is correct
71 Correct 111 ms 164276 KB Output is correct
72 Correct 111 ms 163288 KB Output is correct
73 Correct 86 ms 130892 KB Output is correct
74 Correct 88 ms 131256 KB Output is correct
75 Correct 50 ms 122292 KB Output is correct
76 Correct 51 ms 121840 KB Output is correct
77 Correct 188 ms 263048 KB Output is correct
78 Correct 190 ms 263060 KB Output is correct
79 Correct 241 ms 261644 KB Output is correct
80 Correct 226 ms 261668 KB Output is correct
81 Correct 138 ms 155372 KB Output is correct
82 Correct 130 ms 155104 KB Output is correct
83 Correct 60 ms 128392 KB Output is correct
84 Correct 61 ms 128436 KB Output is correct
85 Correct 65 ms 128540 KB Output is correct
86 Correct 59 ms 128464 KB Output is correct
87 Correct 216 ms 237808 KB Output is correct
88 Correct 198 ms 237888 KB Output is correct
89 Correct 244 ms 256808 KB Output is correct
90 Correct 245 ms 255892 KB Output is correct
91 Correct 162 ms 151164 KB Output is correct
92 Correct 139 ms 150696 KB Output is correct
93 Correct 60 ms 127600 KB Output is correct
94 Correct 61 ms 127504 KB Output is correct
95 Correct 190 ms 228884 KB Output is correct
96 Correct 197 ms 228984 KB Output is correct
97 Correct 271 ms 245612 KB Output is correct
98 Correct 245 ms 244668 KB Output is correct
99 Correct 156 ms 148964 KB Output is correct
100 Correct 168 ms 148736 KB Output is correct
101 Correct 66 ms 127288 KB Output is correct
102 Correct 63 ms 128140 KB Output is correct
103 Correct 281 ms 388804 KB Output is correct
104 Correct 276 ms 388736 KB Output is correct
105 Correct 450 ms 477836 KB Output is correct
106 Correct 449 ms 477516 KB Output is correct
107 Correct 218 ms 185784 KB Output is correct
108 Correct 194 ms 185748 KB Output is correct
109 Correct 83 ms 145548 KB Output is correct
110 Correct 78 ms 145624 KB Output is correct
111 Correct 76 ms 145596 KB Output is correct
112 Correct 79 ms 145612 KB Output is correct
113 Correct 297 ms 342252 KB Output is correct
114 Correct 294 ms 341868 KB Output is correct
115 Runtime error 925 ms 524288 KB Execution killed with signal 11
116 Halted 0 ms 0 KB -