답안 #1007838

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1007838 2024-06-25T14:27:24 Z amirhoseinfar1385 Vinjete (COI22_vinjete) C++17
100 / 100
886 ms 484260 KB
#include<bits/stdc++.h>
using namespace std;
const int maxn=100000+10;
struct yal{
	int u,v,l,r;
	int getad(int fu){
		return (fu^u^v);
	}
}alle[maxn];
vector<int>adj[maxn];
int n,m,kaf=(1<<30),res[maxn];
struct node{
	int mina,lazy,ted,cl,cr,l,r;
	node(){
		mina=lazy=ted=0;
		cl=cr=-1;
	}
}fakenode;

struct segment{
	vector<node>seg;
	segment(){
		seg.resize(2);
		seg[1].l=0;
		seg[1].r=kaf-1;
		seg[1].ted=kaf;
	}
	int getl(int i){
		if(seg[i].cl==-1){
			seg.push_back(fakenode);
			seg[i].cl=(int)seg.size()-1;
			seg.back().l=seg[i].l;
			seg.back().r=(seg[i].l+seg[i].r)/2;
			seg.back().ted=seg.back().r-seg.back().l+1;
		}
		return seg[i].cl;
	}
	int getr(int i){
		if(seg[i].cr==-1){
			seg.push_back(fakenode);
			seg[i].cr=(int)seg.size()-1;
			seg.back().l=(seg[i].l+seg[i].r)/2+1;
			seg.back().r=seg[i].r;
			seg.back().ted=seg.back().r-seg.back().l+1;
		}
		return seg[i].cr;
	}
	node comp(node a,node b){
		if(a.mina<b.mina){
			return a;
		}
		if(b.mina<a.mina){
			return b;
		}
		b.ted+=a.ted;
		return b;
	}
	void calc(int i){
		if(seg[i].l==seg[i].r){
			seg[i].mina+=seg[i].lazy;
			seg[i].lazy=0;
			return ;
		}
		auto x=comp(seg[getl(i)],seg[getr(i)]);
		seg[i].mina=x.mina;
		seg[i].ted=x.ted;
		seg[i].mina+=seg[i].lazy;
	}
	void shift(int i){
		if(seg[i].l==seg[i].r){
			return ;
		}
		seg[getl(i)].lazy+=seg[i].lazy;
		seg[getr(i)].lazy+=seg[i].lazy;
		calc(getl(i));
		calc(getr(i));
		seg[i].lazy=0;
		return ;
	}
	void add(int i,int l,int r,int tl,int tr,int w){
		if(l>r||l>tr||r<tl||tl>tr){
			return ;
		}
		if(l>=tl&&r<=tr){
			seg[i].lazy+=w;
			calc(i);
			//cout<<"wtf: "<<seg[i].lazy<<" "<<seg[i].mina<<" "<<i<<" "<<l<<" "<<r<<endl;
			return ;
		}
		shift(i);
		int m=(l+r)>>1;
		add(getl(i),l,m,tl,tr,w);
		add(getr(i),m+1,r,tl,tr,w);
		calc(i);
	}
	node pors(int i,int l,int r,int tl,int tr){
		if(l>r||l>tr||r<tl||tl>tr){
			node fk;
			fk.mina=maxn+10;
			return fk;
		}
		shift(i);
		calc(i);
		if(l>=tl&&r<=tr){
			//cout<<l<<" "<<r<<" "<<seg[i].mina<<" "<<seg[i].ted<<" "<<seg[i].lazy<<endl;
			return seg[i];
		}
		int m=(l+r)>>1;
		return comp(pors(getl(i),l,m,tl,tr),pors(getr(i),m+1,r,tl,tr));
	}
}seg;

void vorod(){
	cin>>n>>m;
	for(int i=0;i<n;i++){
		cin>>alle[i].u>>alle[i].v>>alle[i].l>>alle[i].r;
		adj[alle[i].u].push_back(i);
		adj[alle[i].v].push_back(i);
	}
}

void dfssolve(int u,int par=-1){
	node a=seg.pors(1,0,kaf-1,1,m);
	//cout<<u<<" "<<a.mina<<endl;
	if(a.mina!=0){
		a.ted=0;
	}
	res[u]=a.ted;
	for(auto x:adj[u]){
		int v=alle[x].getad(u);
		if(v==par){
			continue;
		}
		seg.add(1,0,kaf-1,alle[x].l,alle[x].r,1);
		dfssolve(v,u);
		seg.add(1,0,kaf-1,alle[x].l,alle[x].r,-1);
	}
}

void solve(){
	dfssolve(1);	
}

void khor(){
	for(int i=2;i<=n;i++){
		res[i]=m-res[i];
		cout<<res[i]<<"\n";
	}
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	//cout.tie(0);
	//freopen("inp.txt","r",stdin);
	vorod();
	solve();
	khor();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4696 KB Output is correct
2 Correct 4 ms 4700 KB Output is correct
3 Correct 4 ms 4780 KB Output is correct
4 Correct 4 ms 4700 KB Output is correct
5 Correct 5 ms 4700 KB Output is correct
6 Correct 4 ms 4700 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 4 ms 4444 KB Output is correct
10 Correct 4 ms 4440 KB Output is correct
11 Correct 4 ms 4696 KB Output is correct
12 Correct 4 ms 4700 KB Output is correct
13 Correct 4 ms 4700 KB Output is correct
14 Correct 4 ms 4736 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4540 KB Output is correct
17 Correct 3 ms 4580 KB Output is correct
18 Correct 3 ms 4444 KB Output is correct
19 Correct 4 ms 4736 KB Output is correct
20 Correct 3 ms 4700 KB Output is correct
21 Correct 3 ms 4696 KB Output is correct
22 Correct 3 ms 4700 KB Output is correct
23 Correct 1 ms 4444 KB Output is correct
24 Correct 1 ms 4444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4696 KB Output is correct
2 Correct 4 ms 4700 KB Output is correct
3 Correct 4 ms 4780 KB Output is correct
4 Correct 4 ms 4700 KB Output is correct
5 Correct 5 ms 4700 KB Output is correct
6 Correct 4 ms 4700 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 4 ms 4444 KB Output is correct
10 Correct 4 ms 4440 KB Output is correct
11 Correct 4 ms 4696 KB Output is correct
12 Correct 4 ms 4700 KB Output is correct
13 Correct 4 ms 4700 KB Output is correct
14 Correct 4 ms 4736 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4540 KB Output is correct
17 Correct 3 ms 4580 KB Output is correct
18 Correct 3 ms 4444 KB Output is correct
19 Correct 4 ms 4736 KB Output is correct
20 Correct 3 ms 4700 KB Output is correct
21 Correct 3 ms 4696 KB Output is correct
22 Correct 3 ms 4700 KB Output is correct
23 Correct 1 ms 4444 KB Output is correct
24 Correct 1 ms 4444 KB Output is correct
25 Correct 6 ms 4700 KB Output is correct
26 Correct 5 ms 4700 KB Output is correct
27 Correct 9 ms 12236 KB Output is correct
28 Correct 9 ms 12492 KB Output is correct
29 Correct 7 ms 8400 KB Output is correct
30 Correct 6 ms 9932 KB Output is correct
31 Correct 9 ms 13516 KB Output is correct
32 Correct 8 ms 12652 KB Output is correct
33 Correct 8 ms 13392 KB Output is correct
34 Correct 8 ms 13516 KB Output is correct
35 Correct 6 ms 4700 KB Output is correct
36 Correct 6 ms 4700 KB Output is correct
37 Correct 10 ms 13260 KB Output is correct
38 Correct 11 ms 12836 KB Output is correct
39 Correct 6 ms 8656 KB Output is correct
40 Correct 6 ms 9168 KB Output is correct
41 Correct 8 ms 13660 KB Output is correct
42 Correct 8 ms 12608 KB Output is correct
43 Correct 5 ms 4444 KB Output is correct
44 Correct 5 ms 4700 KB Output is correct
45 Correct 10 ms 12236 KB Output is correct
46 Correct 8 ms 13776 KB Output is correct
47 Correct 6 ms 9348 KB Output is correct
48 Correct 6 ms 8916 KB Output is correct
49 Correct 8 ms 12432 KB Output is correct
50 Correct 9 ms 12496 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4696 KB Output is correct
2 Correct 4 ms 4700 KB Output is correct
3 Correct 4 ms 4780 KB Output is correct
4 Correct 4 ms 4700 KB Output is correct
5 Correct 5 ms 4700 KB Output is correct
6 Correct 4 ms 4700 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 4 ms 4444 KB Output is correct
10 Correct 4 ms 4440 KB Output is correct
11 Correct 4 ms 4696 KB Output is correct
12 Correct 4 ms 4700 KB Output is correct
13 Correct 4 ms 4700 KB Output is correct
14 Correct 4 ms 4736 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4540 KB Output is correct
17 Correct 3 ms 4580 KB Output is correct
18 Correct 3 ms 4444 KB Output is correct
19 Correct 4 ms 4736 KB Output is correct
20 Correct 3 ms 4700 KB Output is correct
21 Correct 3 ms 4696 KB Output is correct
22 Correct 3 ms 4700 KB Output is correct
23 Correct 1 ms 4444 KB Output is correct
24 Correct 1 ms 4444 KB Output is correct
25 Correct 146 ms 12624 KB Output is correct
26 Correct 134 ms 12532 KB Output is correct
27 Correct 154 ms 14856 KB Output is correct
28 Correct 159 ms 15544 KB Output is correct
29 Correct 131 ms 15948 KB Output is correct
30 Correct 125 ms 15808 KB Output is correct
31 Correct 18 ms 7124 KB Output is correct
32 Correct 18 ms 7124 KB Output is correct
33 Correct 18 ms 7120 KB Output is correct
34 Correct 18 ms 7124 KB Output is correct
35 Correct 155 ms 7500 KB Output is correct
36 Correct 142 ms 7764 KB Output is correct
37 Correct 167 ms 12744 KB Output is correct
38 Correct 167 ms 12096 KB Output is correct
39 Correct 126 ms 10684 KB Output is correct
40 Correct 124 ms 11204 KB Output is correct
41 Correct 17 ms 6744 KB Output is correct
42 Correct 17 ms 6840 KB Output is correct
43 Correct 146 ms 6856 KB Output is correct
44 Correct 150 ms 6860 KB Output is correct
45 Correct 166 ms 10952 KB Output is correct
46 Correct 160 ms 10600 KB Output is correct
47 Correct 125 ms 11872 KB Output is correct
48 Correct 127 ms 10616 KB Output is correct
49 Correct 18 ms 6628 KB Output is correct
50 Correct 18 ms 6744 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4696 KB Output is correct
2 Correct 4 ms 4700 KB Output is correct
3 Correct 4 ms 4780 KB Output is correct
4 Correct 4 ms 4700 KB Output is correct
5 Correct 5 ms 4700 KB Output is correct
6 Correct 4 ms 4700 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 4 ms 4444 KB Output is correct
10 Correct 4 ms 4440 KB Output is correct
11 Correct 4 ms 4696 KB Output is correct
12 Correct 4 ms 4700 KB Output is correct
13 Correct 4 ms 4700 KB Output is correct
14 Correct 4 ms 4736 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4540 KB Output is correct
17 Correct 3 ms 4580 KB Output is correct
18 Correct 3 ms 4444 KB Output is correct
19 Correct 4 ms 4736 KB Output is correct
20 Correct 3 ms 4700 KB Output is correct
21 Correct 3 ms 4696 KB Output is correct
22 Correct 3 ms 4700 KB Output is correct
23 Correct 1 ms 4444 KB Output is correct
24 Correct 1 ms 4444 KB Output is correct
25 Correct 146 ms 12624 KB Output is correct
26 Correct 134 ms 12532 KB Output is correct
27 Correct 154 ms 14856 KB Output is correct
28 Correct 159 ms 15544 KB Output is correct
29 Correct 131 ms 15948 KB Output is correct
30 Correct 125 ms 15808 KB Output is correct
31 Correct 18 ms 7124 KB Output is correct
32 Correct 18 ms 7124 KB Output is correct
33 Correct 18 ms 7120 KB Output is correct
34 Correct 18 ms 7124 KB Output is correct
35 Correct 155 ms 7500 KB Output is correct
36 Correct 142 ms 7764 KB Output is correct
37 Correct 167 ms 12744 KB Output is correct
38 Correct 167 ms 12096 KB Output is correct
39 Correct 126 ms 10684 KB Output is correct
40 Correct 124 ms 11204 KB Output is correct
41 Correct 17 ms 6744 KB Output is correct
42 Correct 17 ms 6840 KB Output is correct
43 Correct 146 ms 6856 KB Output is correct
44 Correct 150 ms 6860 KB Output is correct
45 Correct 166 ms 10952 KB Output is correct
46 Correct 160 ms 10600 KB Output is correct
47 Correct 125 ms 11872 KB Output is correct
48 Correct 127 ms 10616 KB Output is correct
49 Correct 18 ms 6628 KB Output is correct
50 Correct 18 ms 6744 KB Output is correct
51 Correct 347 ms 24592 KB Output is correct
52 Correct 358 ms 24660 KB Output is correct
53 Correct 393 ms 31928 KB Output is correct
54 Correct 393 ms 31416 KB Output is correct
55 Correct 328 ms 31164 KB Output is correct
56 Correct 326 ms 31924 KB Output is correct
57 Correct 67 ms 16836 KB Output is correct
58 Correct 69 ms 16576 KB Output is correct
59 Correct 67 ms 16072 KB Output is correct
60 Correct 70 ms 15816 KB Output is correct
61 Correct 343 ms 12372 KB Output is correct
62 Correct 358 ms 12628 KB Output is correct
63 Correct 390 ms 18876 KB Output is correct
64 Correct 405 ms 18624 KB Output is correct
65 Correct 286 ms 21336 KB Output is correct
66 Correct 288 ms 20412 KB Output is correct
67 Correct 65 ms 14392 KB Output is correct
68 Correct 63 ms 14276 KB Output is correct
69 Correct 377 ms 10576 KB Output is correct
70 Correct 363 ms 10576 KB Output is correct
71 Correct 440 ms 18872 KB Output is correct
72 Correct 375 ms 17592 KB Output is correct
73 Correct 298 ms 19516 KB Output is correct
74 Correct 298 ms 18876 KB Output is correct
75 Correct 70 ms 13592 KB Output is correct
76 Correct 70 ms 15044 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4696 KB Output is correct
2 Correct 4 ms 4700 KB Output is correct
3 Correct 4 ms 4780 KB Output is correct
4 Correct 4 ms 4700 KB Output is correct
5 Correct 5 ms 4700 KB Output is correct
6 Correct 4 ms 4700 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 4 ms 4444 KB Output is correct
10 Correct 4 ms 4440 KB Output is correct
11 Correct 4 ms 4696 KB Output is correct
12 Correct 4 ms 4700 KB Output is correct
13 Correct 4 ms 4700 KB Output is correct
14 Correct 4 ms 4736 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4540 KB Output is correct
17 Correct 3 ms 4580 KB Output is correct
18 Correct 3 ms 4444 KB Output is correct
19 Correct 4 ms 4736 KB Output is correct
20 Correct 3 ms 4700 KB Output is correct
21 Correct 3 ms 4696 KB Output is correct
22 Correct 3 ms 4700 KB Output is correct
23 Correct 1 ms 4444 KB Output is correct
24 Correct 1 ms 4444 KB Output is correct
25 Correct 6 ms 4700 KB Output is correct
26 Correct 5 ms 4700 KB Output is correct
27 Correct 9 ms 12236 KB Output is correct
28 Correct 9 ms 12492 KB Output is correct
29 Correct 7 ms 8400 KB Output is correct
30 Correct 6 ms 9932 KB Output is correct
31 Correct 9 ms 13516 KB Output is correct
32 Correct 8 ms 12652 KB Output is correct
33 Correct 8 ms 13392 KB Output is correct
34 Correct 8 ms 13516 KB Output is correct
35 Correct 6 ms 4700 KB Output is correct
36 Correct 6 ms 4700 KB Output is correct
37 Correct 10 ms 13260 KB Output is correct
38 Correct 11 ms 12836 KB Output is correct
39 Correct 6 ms 8656 KB Output is correct
40 Correct 6 ms 9168 KB Output is correct
41 Correct 8 ms 13660 KB Output is correct
42 Correct 8 ms 12608 KB Output is correct
43 Correct 5 ms 4444 KB Output is correct
44 Correct 5 ms 4700 KB Output is correct
45 Correct 10 ms 12236 KB Output is correct
46 Correct 8 ms 13776 KB Output is correct
47 Correct 6 ms 9348 KB Output is correct
48 Correct 6 ms 8916 KB Output is correct
49 Correct 8 ms 12432 KB Output is correct
50 Correct 9 ms 12496 KB Output is correct
51 Correct 146 ms 12624 KB Output is correct
52 Correct 134 ms 12532 KB Output is correct
53 Correct 154 ms 14856 KB Output is correct
54 Correct 159 ms 15544 KB Output is correct
55 Correct 131 ms 15948 KB Output is correct
56 Correct 125 ms 15808 KB Output is correct
57 Correct 18 ms 7124 KB Output is correct
58 Correct 18 ms 7124 KB Output is correct
59 Correct 18 ms 7120 KB Output is correct
60 Correct 18 ms 7124 KB Output is correct
61 Correct 155 ms 7500 KB Output is correct
62 Correct 142 ms 7764 KB Output is correct
63 Correct 167 ms 12744 KB Output is correct
64 Correct 167 ms 12096 KB Output is correct
65 Correct 126 ms 10684 KB Output is correct
66 Correct 124 ms 11204 KB Output is correct
67 Correct 17 ms 6744 KB Output is correct
68 Correct 17 ms 6840 KB Output is correct
69 Correct 146 ms 6856 KB Output is correct
70 Correct 150 ms 6860 KB Output is correct
71 Correct 166 ms 10952 KB Output is correct
72 Correct 160 ms 10600 KB Output is correct
73 Correct 125 ms 11872 KB Output is correct
74 Correct 127 ms 10616 KB Output is correct
75 Correct 18 ms 6628 KB Output is correct
76 Correct 18 ms 6744 KB Output is correct
77 Correct 347 ms 24592 KB Output is correct
78 Correct 358 ms 24660 KB Output is correct
79 Correct 393 ms 31928 KB Output is correct
80 Correct 393 ms 31416 KB Output is correct
81 Correct 328 ms 31164 KB Output is correct
82 Correct 326 ms 31924 KB Output is correct
83 Correct 67 ms 16836 KB Output is correct
84 Correct 69 ms 16576 KB Output is correct
85 Correct 67 ms 16072 KB Output is correct
86 Correct 70 ms 15816 KB Output is correct
87 Correct 343 ms 12372 KB Output is correct
88 Correct 358 ms 12628 KB Output is correct
89 Correct 390 ms 18876 KB Output is correct
90 Correct 405 ms 18624 KB Output is correct
91 Correct 286 ms 21336 KB Output is correct
92 Correct 288 ms 20412 KB Output is correct
93 Correct 65 ms 14392 KB Output is correct
94 Correct 63 ms 14276 KB Output is correct
95 Correct 377 ms 10576 KB Output is correct
96 Correct 363 ms 10576 KB Output is correct
97 Correct 440 ms 18872 KB Output is correct
98 Correct 375 ms 17592 KB Output is correct
99 Correct 298 ms 19516 KB Output is correct
100 Correct 298 ms 18876 KB Output is correct
101 Correct 70 ms 13592 KB Output is correct
102 Correct 70 ms 15044 KB Output is correct
103 Correct 466 ms 25448 KB Output is correct
104 Correct 457 ms 25428 KB Output is correct
105 Correct 886 ms 484260 KB Output is correct
106 Correct 878 ms 484228 KB Output is correct
107 Correct 496 ms 253072 KB Output is correct
108 Correct 479 ms 254268 KB Output is correct
109 Correct 127 ms 123808 KB Output is correct
110 Correct 125 ms 124504 KB Output is correct
111 Correct 113 ms 125600 KB Output is correct
112 Correct 118 ms 124824 KB Output is correct
113 Correct 447 ms 13560 KB Output is correct
114 Correct 445 ms 13140 KB Output is correct
115 Correct 768 ms 472420 KB Output is correct
116 Correct 774 ms 472700 KB Output is correct
117 Correct 448 ms 244368 KB Output is correct
118 Correct 483 ms 243604 KB Output is correct
119 Correct 111 ms 122260 KB Output is correct
120 Correct 117 ms 121504 KB Output is correct
121 Correct 452 ms 11344 KB Output is correct
122 Correct 488 ms 11224 KB Output is correct
123 Correct 755 ms 470664 KB Output is correct
124 Correct 791 ms 470876 KB Output is correct
125 Correct 480 ms 242312 KB Output is correct
126 Correct 485 ms 241288 KB Output is correct
127 Correct 142 ms 120988 KB Output is correct
128 Correct 138 ms 122524 KB Output is correct