Submission #745243

# Submission time Handle Problem Language Result Execution time Memory
745243 2023-05-19T15:31:08 Z sword060 Osumnjičeni (COCI21_osumnjiceni) C++17
110 / 110
883 ms 149496 KB
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5+5,M=18;
struct Node{
	int l=-1,r=-1,mx=0,lzy=-1;
};
vector<Node>t(1);
void prop(int i){
	if(t[i].lzy==-1)return;
	if(t[i].l==-1){
		t[i].l=t.size();
		t.emplace_back();
	}
	if(t[i].r==-1){
		t[i].r=t.size();
		t.emplace_back();
	}
	t[t[i].l].mx=max(t[t[i].l].mx,t[i].lzy);
	t[t[i].r].mx=max(t[t[i].r].mx,t[i].lzy);
	t[t[i].l].lzy=max(t[t[i].l].lzy,t[i].lzy);
	t[t[i].r].lzy=max(t[t[i].r].lzy,t[i].lzy);
	t[i].lzy=-1;
}
int get(int i,int l,int r,int s,int e){
	if(l>=s&&r<=e)return t[i].mx;
	if(l>e||r<s)return 0;
	int mid=(l+r)/2;
	prop(i);
	if(t[i].l==-1){
		t[i].l=t.size();
		t.emplace_back();
	}
	if(t[i].r==-1){
		t[i].r=t.size();
		t.emplace_back();
	}
	return max(get(t[i].l,l,mid,s,e),get(t[i].r,mid+1,r,s,e));
}
void upd(int i,int l,int r,int s,int e,int v){
	if(l>=s&&r<=e){
		t[i].mx=max(t[i].mx,v);
		t[i].lzy=v;
		return;
	}
	if(l>e||r<s)return;
	int mid=(l+r)/2;
	if(t[i].l==-1){
		t[i].l=t.size();
		t.emplace_back();
	}
	if(t[i].r==-1){
		t[i].r=t.size();
		t.emplace_back();
	}
	upd(t[i].l,l,mid,s,e,v);upd(t[i].r,mid+1,r,s,e,v);
	t[i].mx=max(t[t[i].l].mx,t[t[i].r].mx);
}
int x,q,l[N],r[N],nxt[N][20];
int main(){
	ios::sync_with_stdio(0);cin.tie(0);
	cin>>x;
	for(int i=1;i<=x;i++)cin>>l[i]>>r[i];
	for(int i=1;i<=x;i++){
		nxt[i][0]=max(nxt[i-1][0],get(0,1,1e9,l[i],r[i]));
		upd(0,1,1e9,l[i],r[i],i);
		for(int j=1;j<=M;j++)
			nxt[i][j]=nxt[nxt[i][j-1]][j-1];
	}
	cin>>q;
	while(q--){
		int c1,c2,ans=1;cin>>c1>>c2;
		for(int i=M;i>=0;i--)
			if(nxt[c2][i]>=c1)
				c2=nxt[c2][i],ans+=(1<<i);
		cout<<ans<<"\n";
	}
}
# Verdict Execution time Memory Grader output
1 Correct 686 ms 143716 KB Output is correct
2 Correct 672 ms 141284 KB Output is correct
3 Correct 631 ms 141600 KB Output is correct
4 Correct 658 ms 143120 KB Output is correct
5 Correct 663 ms 148496 KB Output is correct
6 Correct 156 ms 16444 KB Output is correct
7 Correct 163 ms 16720 KB Output is correct
8 Correct 164 ms 16988 KB Output is correct
9 Correct 180 ms 17284 KB Output is correct
10 Correct 186 ms 16844 KB Output is correct
11 Correct 323 ms 82352 KB Output is correct
12 Correct 329 ms 77484 KB Output is correct
13 Correct 312 ms 77272 KB Output is correct
14 Correct 329 ms 82556 KB Output is correct
15 Correct 327 ms 80248 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 175 ms 17616 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 9160 KB Output is correct
2 Correct 18 ms 9232 KB Output is correct
3 Correct 18 ms 9160 KB Output is correct
4 Correct 19 ms 9184 KB Output is correct
5 Correct 17 ms 9096 KB Output is correct
6 Correct 7 ms 852 KB Output is correct
7 Correct 6 ms 852 KB Output is correct
8 Correct 6 ms 852 KB Output is correct
9 Correct 6 ms 980 KB Output is correct
10 Correct 7 ms 852 KB Output is correct
11 Correct 10 ms 2896 KB Output is correct
12 Correct 8 ms 2896 KB Output is correct
13 Correct 9 ms 2896 KB Output is correct
14 Correct 9 ms 2896 KB Output is correct
15 Correct 9 ms 2896 KB Output is correct
16 Correct 1 ms 324 KB Output is correct
17 Correct 6 ms 916 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 9160 KB Output is correct
2 Correct 18 ms 9232 KB Output is correct
3 Correct 18 ms 9160 KB Output is correct
4 Correct 19 ms 9184 KB Output is correct
5 Correct 17 ms 9096 KB Output is correct
6 Correct 7 ms 852 KB Output is correct
7 Correct 6 ms 852 KB Output is correct
8 Correct 6 ms 852 KB Output is correct
9 Correct 6 ms 980 KB Output is correct
10 Correct 7 ms 852 KB Output is correct
11 Correct 10 ms 2896 KB Output is correct
12 Correct 8 ms 2896 KB Output is correct
13 Correct 9 ms 2896 KB Output is correct
14 Correct 9 ms 2896 KB Output is correct
15 Correct 9 ms 2896 KB Output is correct
16 Correct 1 ms 324 KB Output is correct
17 Correct 6 ms 916 KB Output is correct
18 Correct 86 ms 9036 KB Output is correct
19 Correct 75 ms 9160 KB Output is correct
20 Correct 84 ms 9032 KB Output is correct
21 Correct 77 ms 9228 KB Output is correct
22 Correct 80 ms 9188 KB Output is correct
23 Correct 66 ms 2368 KB Output is correct
24 Correct 69 ms 2440 KB Output is correct
25 Correct 67 ms 2368 KB Output is correct
26 Correct 65 ms 2368 KB Output is correct
27 Correct 64 ms 2276 KB Output is correct
28 Correct 53 ms 3632 KB Output is correct
29 Correct 58 ms 3676 KB Output is correct
30 Correct 59 ms 3640 KB Output is correct
31 Correct 56 ms 3652 KB Output is correct
32 Correct 52 ms 3736 KB Output is correct
33 Correct 1 ms 324 KB Output is correct
34 Correct 55 ms 2668 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 689 ms 149396 KB Output is correct
2 Correct 663 ms 146252 KB Output is correct
3 Correct 628 ms 140968 KB Output is correct
4 Correct 621 ms 140848 KB Output is correct
5 Correct 632 ms 141060 KB Output is correct
6 Correct 162 ms 16600 KB Output is correct
7 Correct 161 ms 16628 KB Output is correct
8 Correct 162 ms 16604 KB Output is correct
9 Correct 170 ms 16460 KB Output is correct
10 Correct 195 ms 17840 KB Output is correct
11 Correct 376 ms 76876 KB Output is correct
12 Correct 388 ms 149496 KB Output is correct
13 Correct 309 ms 76720 KB Output is correct
14 Correct 316 ms 79180 KB Output is correct
15 Correct 338 ms 83728 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 160 ms 16912 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 686 ms 143716 KB Output is correct
2 Correct 672 ms 141284 KB Output is correct
3 Correct 631 ms 141600 KB Output is correct
4 Correct 658 ms 143120 KB Output is correct
5 Correct 663 ms 148496 KB Output is correct
6 Correct 156 ms 16444 KB Output is correct
7 Correct 163 ms 16720 KB Output is correct
8 Correct 164 ms 16988 KB Output is correct
9 Correct 180 ms 17284 KB Output is correct
10 Correct 186 ms 16844 KB Output is correct
11 Correct 323 ms 82352 KB Output is correct
12 Correct 329 ms 77484 KB Output is correct
13 Correct 312 ms 77272 KB Output is correct
14 Correct 329 ms 82556 KB Output is correct
15 Correct 327 ms 80248 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 175 ms 17616 KB Output is correct
18 Correct 18 ms 9160 KB Output is correct
19 Correct 18 ms 9232 KB Output is correct
20 Correct 18 ms 9160 KB Output is correct
21 Correct 19 ms 9184 KB Output is correct
22 Correct 17 ms 9096 KB Output is correct
23 Correct 7 ms 852 KB Output is correct
24 Correct 6 ms 852 KB Output is correct
25 Correct 6 ms 852 KB Output is correct
26 Correct 6 ms 980 KB Output is correct
27 Correct 7 ms 852 KB Output is correct
28 Correct 10 ms 2896 KB Output is correct
29 Correct 8 ms 2896 KB Output is correct
30 Correct 9 ms 2896 KB Output is correct
31 Correct 9 ms 2896 KB Output is correct
32 Correct 9 ms 2896 KB Output is correct
33 Correct 1 ms 324 KB Output is correct
34 Correct 6 ms 916 KB Output is correct
35 Correct 86 ms 9036 KB Output is correct
36 Correct 75 ms 9160 KB Output is correct
37 Correct 84 ms 9032 KB Output is correct
38 Correct 77 ms 9228 KB Output is correct
39 Correct 80 ms 9188 KB Output is correct
40 Correct 66 ms 2368 KB Output is correct
41 Correct 69 ms 2440 KB Output is correct
42 Correct 67 ms 2368 KB Output is correct
43 Correct 65 ms 2368 KB Output is correct
44 Correct 64 ms 2276 KB Output is correct
45 Correct 53 ms 3632 KB Output is correct
46 Correct 58 ms 3676 KB Output is correct
47 Correct 59 ms 3640 KB Output is correct
48 Correct 56 ms 3652 KB Output is correct
49 Correct 52 ms 3736 KB Output is correct
50 Correct 1 ms 324 KB Output is correct
51 Correct 55 ms 2668 KB Output is correct
52 Correct 689 ms 149396 KB Output is correct
53 Correct 663 ms 146252 KB Output is correct
54 Correct 628 ms 140968 KB Output is correct
55 Correct 621 ms 140848 KB Output is correct
56 Correct 632 ms 141060 KB Output is correct
57 Correct 162 ms 16600 KB Output is correct
58 Correct 161 ms 16628 KB Output is correct
59 Correct 162 ms 16604 KB Output is correct
60 Correct 170 ms 16460 KB Output is correct
61 Correct 195 ms 17840 KB Output is correct
62 Correct 376 ms 76876 KB Output is correct
63 Correct 388 ms 149496 KB Output is correct
64 Correct 309 ms 76720 KB Output is correct
65 Correct 316 ms 79180 KB Output is correct
66 Correct 338 ms 83728 KB Output is correct
67 Correct 1 ms 212 KB Output is correct
68 Correct 160 ms 16912 KB Output is correct
69 Correct 797 ms 141084 KB Output is correct
70 Correct 883 ms 147892 KB Output is correct
71 Correct 793 ms 140864 KB Output is correct
72 Correct 847 ms 144336 KB Output is correct
73 Correct 832 ms 142000 KB Output is correct
74 Correct 374 ms 19148 KB Output is correct
75 Correct 356 ms 17740 KB Output is correct
76 Correct 334 ms 19124 KB Output is correct
77 Correct 334 ms 17652 KB Output is correct
78 Correct 308 ms 17900 KB Output is correct
79 Correct 398 ms 84088 KB Output is correct
80 Correct 367 ms 77908 KB Output is correct
81 Correct 369 ms 77280 KB Output is correct
82 Correct 413 ms 81712 KB Output is correct
83 Correct 405 ms 77932 KB Output is correct
84 Correct 1 ms 340 KB Output is correct
85 Correct 231 ms 17960 KB Output is correct