Submission #998427

# Submission time Handle Problem Language Result Execution time Memory
998427 2024-06-14T01:24:28 Z amirhoseinfar1385 Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
100 / 100
1288 ms 75208 KB
#include<bits/stdc++.h>
using namespace std;
const int maxn=1000000+10;
int all[maxn],n,q,kaf=(1<<20),tr[maxn];

struct segment{
	pair<int,int>seg[(1<<21)];
	void ins(int i,pair<int,int>w){
		i+=kaf;
		while(i>0){
			seg[i]=max(seg[i],w);
			i>>=1;
		}
	}
	pair<int,int>pors(int i,int l,int r,int tl,int tr){
		if(l>r||l>tr||r<tl||tl>tr){
			return make_pair(0,0);
		}
		if(l>=tl&&r<=tr){
			return seg[i];
		}
		int m=(l+r)>>1;
		return max(pors((i<<1),l,m,tl,tr),pors((i<<1)^1,m+1,r,tl,tr));
	}
}seg,sega;

void vorod(){
	cin>>n>>q;
	for(int i=1;i<=n;i++){
		cin>>all[i];
	}
}

void pre(){
	for(int i=1;i<=n;i++){
		seg.ins(i,make_pair(all[i],i));
	}
	vector<int>v;
	for(int i=n;i>=1;i--){
		while((int)v.size()>0&&all[i]>all[v.back()]){
			v.pop_back();
		}
		if((int)v.size()>0){
			tr[i]=v.back();
		}else{
			tr[i]=n+1;
		}
		v.push_back(i);
	}
	for(int i=1;i<=n;i++){
		if(tr[i]==i+1){
			continue;
		}
		sega.ins(i,make_pair(all[i]+seg.pors(1,0,kaf-1,i+1,tr[i]-1).first,i));
	}
}

int calc(int l,int r,int w){
	if(l>r){
		return 1;
	}
	pair<int,int>p=seg.pors(1,0,kaf-1,l,r);
	if(p.second!=r){
		pair<int,int>pp=seg.pors(1,0,kaf-1,p.second+1,r);
		if(p.first+pp.first>w){
			return 0;
		}
	}
	if(p.second==l){
		return 1;
	}
	return sega.pors(1,0,kaf-1,l,p.second-1).first<=w;
}

void solve(){
	for(int i=0;i<q;i++){
		int l,r,w;
		cin>>l>>r>>w;
		cout<<calc(l,r,w)<<"\n";
	}
}

int main(){
	ios::sync_with_stdio(0);
	cout.tie(0);
	cin.tie(0);
	vorod();
	pre();
	solve();
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 856 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 856 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 3 ms 604 KB Output is correct
12 Correct 3 ms 888 KB Output is correct
13 Correct 3 ms 860 KB Output is correct
14 Correct 5 ms 952 KB Output is correct
15 Correct 5 ms 860 KB Output is correct
16 Correct 4 ms 860 KB Output is correct
17 Correct 4 ms 716 KB Output is correct
18 Correct 6 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1191 ms 73300 KB Output is correct
2 Correct 1122 ms 74316 KB Output is correct
3 Correct 1174 ms 74576 KB Output is correct
4 Correct 1135 ms 74484 KB Output is correct
5 Correct 1092 ms 58984 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 102 ms 6480 KB Output is correct
2 Correct 103 ms 6740 KB Output is correct
3 Correct 91 ms 5152 KB Output is correct
4 Correct 90 ms 5176 KB Output is correct
5 Correct 90 ms 5180 KB Output is correct
6 Correct 80 ms 4964 KB Output is correct
7 Correct 78 ms 4960 KB Output is correct
8 Correct 81 ms 4892 KB Output is correct
9 Correct 52 ms 1876 KB Output is correct
10 Correct 80 ms 4868 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 856 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 3 ms 604 KB Output is correct
12 Correct 3 ms 888 KB Output is correct
13 Correct 3 ms 860 KB Output is correct
14 Correct 5 ms 952 KB Output is correct
15 Correct 5 ms 860 KB Output is correct
16 Correct 4 ms 860 KB Output is correct
17 Correct 4 ms 716 KB Output is correct
18 Correct 6 ms 604 KB Output is correct
19 Correct 264 ms 15176 KB Output is correct
20 Correct 227 ms 15248 KB Output is correct
21 Correct 216 ms 15400 KB Output is correct
22 Correct 209 ms 15176 KB Output is correct
23 Correct 228 ms 15184 KB Output is correct
24 Correct 181 ms 12208 KB Output is correct
25 Correct 183 ms 11896 KB Output is correct
26 Correct 190 ms 12108 KB Output is correct
27 Correct 185 ms 12208 KB Output is correct
28 Correct 188 ms 12300 KB Output is correct
29 Correct 192 ms 12356 KB Output is correct
30 Correct 204 ms 12224 KB Output is correct
31 Correct 194 ms 12204 KB Output is correct
32 Correct 175 ms 12208 KB Output is correct
33 Correct 180 ms 12204 KB Output is correct
34 Correct 163 ms 11952 KB Output is correct
35 Correct 159 ms 11984 KB Output is correct
36 Correct 167 ms 11808 KB Output is correct
37 Correct 171 ms 11680 KB Output is correct
38 Correct 174 ms 11988 KB Output is correct
39 Correct 189 ms 11864 KB Output is correct
40 Correct 155 ms 8512 KB Output is correct
41 Correct 177 ms 10360 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 856 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 3 ms 604 KB Output is correct
12 Correct 3 ms 888 KB Output is correct
13 Correct 3 ms 860 KB Output is correct
14 Correct 5 ms 952 KB Output is correct
15 Correct 5 ms 860 KB Output is correct
16 Correct 4 ms 860 KB Output is correct
17 Correct 4 ms 716 KB Output is correct
18 Correct 6 ms 604 KB Output is correct
19 Correct 1191 ms 73300 KB Output is correct
20 Correct 1122 ms 74316 KB Output is correct
21 Correct 1174 ms 74576 KB Output is correct
22 Correct 1135 ms 74484 KB Output is correct
23 Correct 1092 ms 58984 KB Output is correct
24 Correct 102 ms 6480 KB Output is correct
25 Correct 103 ms 6740 KB Output is correct
26 Correct 91 ms 5152 KB Output is correct
27 Correct 90 ms 5176 KB Output is correct
28 Correct 90 ms 5180 KB Output is correct
29 Correct 80 ms 4964 KB Output is correct
30 Correct 78 ms 4960 KB Output is correct
31 Correct 81 ms 4892 KB Output is correct
32 Correct 52 ms 1876 KB Output is correct
33 Correct 80 ms 4868 KB Output is correct
34 Correct 264 ms 15176 KB Output is correct
35 Correct 227 ms 15248 KB Output is correct
36 Correct 216 ms 15400 KB Output is correct
37 Correct 209 ms 15176 KB Output is correct
38 Correct 228 ms 15184 KB Output is correct
39 Correct 181 ms 12208 KB Output is correct
40 Correct 183 ms 11896 KB Output is correct
41 Correct 190 ms 12108 KB Output is correct
42 Correct 185 ms 12208 KB Output is correct
43 Correct 188 ms 12300 KB Output is correct
44 Correct 192 ms 12356 KB Output is correct
45 Correct 204 ms 12224 KB Output is correct
46 Correct 194 ms 12204 KB Output is correct
47 Correct 175 ms 12208 KB Output is correct
48 Correct 180 ms 12204 KB Output is correct
49 Correct 163 ms 11952 KB Output is correct
50 Correct 159 ms 11984 KB Output is correct
51 Correct 167 ms 11808 KB Output is correct
52 Correct 171 ms 11680 KB Output is correct
53 Correct 174 ms 11988 KB Output is correct
54 Correct 189 ms 11864 KB Output is correct
55 Correct 155 ms 8512 KB Output is correct
56 Correct 177 ms 10360 KB Output is correct
57 Correct 1288 ms 75208 KB Output is correct
58 Correct 1214 ms 75088 KB Output is correct
59 Correct 1230 ms 75116 KB Output is correct
60 Correct 1227 ms 75092 KB Output is correct
61 Correct 1250 ms 74912 KB Output is correct
62 Correct 1234 ms 74832 KB Output is correct
63 Correct 889 ms 57700 KB Output is correct
64 Correct 951 ms 57716 KB Output is correct
65 Correct 1096 ms 59396 KB Output is correct
66 Correct 1082 ms 59372 KB Output is correct
67 Correct 1049 ms 59520 KB Output is correct
68 Correct 1070 ms 59748 KB Output is correct
69 Correct 1057 ms 59672 KB Output is correct
70 Correct 1092 ms 59620 KB Output is correct
71 Correct 1059 ms 59600 KB Output is correct
72 Correct 1000 ms 59752 KB Output is correct
73 Correct 831 ms 56324 KB Output is correct
74 Correct 859 ms 57272 KB Output is correct
75 Correct 859 ms 56164 KB Output is correct
76 Correct 924 ms 56200 KB Output is correct
77 Correct 863 ms 56164 KB Output is correct
78 Correct 1069 ms 58748 KB Output is correct
79 Correct 779 ms 37556 KB Output is correct
80 Correct 1037 ms 50708 KB Output is correct