Submission #235309

# Submission time Handle Problem Language Result Execution time Memory
235309 2020-05-27T16:25:54 Z keta_tsimakuridze Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++14
100 / 100
1793 ms 131448 KB
#include<bits/stdc++.h>
#define f first
#define s second
using namespace std;
long long n,m,k,a[1000006],cur,x[1000006],tree[4*1000006],i,ans[1000006];
vector<int>v[1000006];
pair< pair<int,int> , pair<int,int> > p[1000006];
void update(int u,int ind,int l,int r,int val){
	if(l>ind || r<ind) return;
	if(l==r) {
		tree[u]=val; return;
	}
	int mid=(l+r)/2;
	update(2*u,ind,l,mid,val);
	update(2*u+1,ind,mid+1,r,val);
	tree[u]=max(tree[2*u],tree[2*u+1]);
}
int getans(int u,int start,int end,int l,int r){
	if(l>end|| r<start) return 0;
	if(start<=l && r<=end) return tree[u];
	int mid=(l+r)/2;
	return max(getans(2*u,start,end,l,mid),getans(2*u+1,start,end,mid+1,r));
}
int main(){
	ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
	cin>>n>>m;
	for(k=1;k<=n;k++){
		cin>>a[k];
		
		cur=k-1;
		while(a[cur]<=a[k] && cur!=0){
			cur=x[cur];
		}
		x[k]=cur;
		
		if(cur!=0) update(1,k,1,n,a[cur]+a[k]),
		v[cur].push_back(k);
	
	}
	
	for(k=1;k<=m;k++){
		cin>>p[k].f.f>>p[k].f.s>>p[k].s.f;
		p[k].s.s=k;
	}
	sort(p+1,p+m+1);
	i=1;
	for(k=1;k<=m;k++){
	
		while(i<p[k].f.f){
		
			for(int j=0;j<v[i].size();j++)
			update(1,v[i][j],1,n,0);
			
			i++;
		}
	
		if(getans(1,p[k].f.f,p[k].f.s,1,n)>p[k].s.f)ans[p[k].s.s]=0;
		else ans[p[k].s.s]=1;
	}
	for(k=1;k<=m;k++)
	cout<<ans[k]<<" ";
}

Compilation message

sortbooks.cpp: In function 'int main()':
sortbooks.cpp:51:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for(int j=0;j<v[i].size();j++)
                ~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 18 ms 23808 KB Output is correct
2 Correct 18 ms 23936 KB Output is correct
3 Correct 18 ms 23936 KB Output is correct
4 Correct 18 ms 23936 KB Output is correct
5 Correct 20 ms 23936 KB Output is correct
6 Correct 19 ms 23936 KB Output is correct
7 Correct 19 ms 23936 KB Output is correct
8 Correct 19 ms 23936 KB Output is correct
9 Correct 18 ms 23808 KB Output is correct
10 Correct 18 ms 23936 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 23808 KB Output is correct
2 Correct 18 ms 23936 KB Output is correct
3 Correct 18 ms 23936 KB Output is correct
4 Correct 18 ms 23936 KB Output is correct
5 Correct 20 ms 23936 KB Output is correct
6 Correct 19 ms 23936 KB Output is correct
7 Correct 19 ms 23936 KB Output is correct
8 Correct 19 ms 23936 KB Output is correct
9 Correct 18 ms 23808 KB Output is correct
10 Correct 18 ms 23936 KB Output is correct
11 Correct 21 ms 24064 KB Output is correct
12 Correct 23 ms 24320 KB Output is correct
13 Correct 24 ms 24320 KB Output is correct
14 Correct 25 ms 24448 KB Output is correct
15 Correct 25 ms 24448 KB Output is correct
16 Correct 22 ms 24192 KB Output is correct
17 Correct 22 ms 24192 KB Output is correct
18 Correct 24 ms 24312 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1696 ms 98680 KB Output is correct
2 Correct 1793 ms 112900 KB Output is correct
3 Correct 1761 ms 112004 KB Output is correct
4 Correct 1779 ms 111992 KB Output is correct
5 Correct 1148 ms 79608 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 152 ms 32504 KB Output is correct
2 Correct 136 ms 32488 KB Output is correct
3 Correct 105 ms 28896 KB Output is correct
4 Correct 108 ms 28924 KB Output is correct
5 Correct 104 ms 28920 KB Output is correct
6 Correct 99 ms 29176 KB Output is correct
7 Correct 106 ms 29304 KB Output is correct
8 Correct 117 ms 30712 KB Output is correct
9 Correct 69 ms 27256 KB Output is correct
10 Correct 123 ms 30364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 23808 KB Output is correct
2 Correct 18 ms 23936 KB Output is correct
3 Correct 18 ms 23936 KB Output is correct
4 Correct 18 ms 23936 KB Output is correct
5 Correct 20 ms 23936 KB Output is correct
6 Correct 19 ms 23936 KB Output is correct
7 Correct 19 ms 23936 KB Output is correct
8 Correct 19 ms 23936 KB Output is correct
9 Correct 18 ms 23808 KB Output is correct
10 Correct 18 ms 23936 KB Output is correct
11 Correct 21 ms 24064 KB Output is correct
12 Correct 23 ms 24320 KB Output is correct
13 Correct 24 ms 24320 KB Output is correct
14 Correct 25 ms 24448 KB Output is correct
15 Correct 25 ms 24448 KB Output is correct
16 Correct 22 ms 24192 KB Output is correct
17 Correct 22 ms 24192 KB Output is correct
18 Correct 24 ms 24312 KB Output is correct
19 Correct 337 ms 40440 KB Output is correct
20 Correct 334 ms 40392 KB Output is correct
21 Correct 285 ms 40440 KB Output is correct
22 Correct 286 ms 40312 KB Output is correct
23 Correct 279 ms 40440 KB Output is correct
24 Correct 224 ms 33016 KB Output is correct
25 Correct 214 ms 33016 KB Output is correct
26 Correct 233 ms 33016 KB Output is correct
27 Correct 218 ms 33016 KB Output is correct
28 Correct 219 ms 33016 KB Output is correct
29 Correct 229 ms 33016 KB Output is correct
30 Correct 235 ms 33016 KB Output is correct
31 Correct 229 ms 33020 KB Output is correct
32 Correct 219 ms 32888 KB Output is correct
33 Correct 232 ms 32888 KB Output is correct
34 Correct 222 ms 32888 KB Output is correct
35 Correct 207 ms 32888 KB Output is correct
36 Correct 213 ms 32888 KB Output is correct
37 Correct 211 ms 32888 KB Output is correct
38 Correct 208 ms 33016 KB Output is correct
39 Correct 225 ms 35192 KB Output is correct
40 Correct 177 ms 32504 KB Output is correct
41 Correct 225 ms 35828 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 23808 KB Output is correct
2 Correct 18 ms 23936 KB Output is correct
3 Correct 18 ms 23936 KB Output is correct
4 Correct 18 ms 23936 KB Output is correct
5 Correct 20 ms 23936 KB Output is correct
6 Correct 19 ms 23936 KB Output is correct
7 Correct 19 ms 23936 KB Output is correct
8 Correct 19 ms 23936 KB Output is correct
9 Correct 18 ms 23808 KB Output is correct
10 Correct 18 ms 23936 KB Output is correct
11 Correct 21 ms 24064 KB Output is correct
12 Correct 23 ms 24320 KB Output is correct
13 Correct 24 ms 24320 KB Output is correct
14 Correct 25 ms 24448 KB Output is correct
15 Correct 25 ms 24448 KB Output is correct
16 Correct 22 ms 24192 KB Output is correct
17 Correct 22 ms 24192 KB Output is correct
18 Correct 24 ms 24312 KB Output is correct
19 Correct 1696 ms 98680 KB Output is correct
20 Correct 1793 ms 112900 KB Output is correct
21 Correct 1761 ms 112004 KB Output is correct
22 Correct 1779 ms 111992 KB Output is correct
23 Correct 1148 ms 79608 KB Output is correct
24 Correct 152 ms 32504 KB Output is correct
25 Correct 136 ms 32488 KB Output is correct
26 Correct 105 ms 28896 KB Output is correct
27 Correct 108 ms 28924 KB Output is correct
28 Correct 104 ms 28920 KB Output is correct
29 Correct 99 ms 29176 KB Output is correct
30 Correct 106 ms 29304 KB Output is correct
31 Correct 117 ms 30712 KB Output is correct
32 Correct 69 ms 27256 KB Output is correct
33 Correct 123 ms 30364 KB Output is correct
34 Correct 337 ms 40440 KB Output is correct
35 Correct 334 ms 40392 KB Output is correct
36 Correct 285 ms 40440 KB Output is correct
37 Correct 286 ms 40312 KB Output is correct
38 Correct 279 ms 40440 KB Output is correct
39 Correct 224 ms 33016 KB Output is correct
40 Correct 214 ms 33016 KB Output is correct
41 Correct 233 ms 33016 KB Output is correct
42 Correct 218 ms 33016 KB Output is correct
43 Correct 219 ms 33016 KB Output is correct
44 Correct 229 ms 33016 KB Output is correct
45 Correct 235 ms 33016 KB Output is correct
46 Correct 229 ms 33020 KB Output is correct
47 Correct 219 ms 32888 KB Output is correct
48 Correct 232 ms 32888 KB Output is correct
49 Correct 222 ms 32888 KB Output is correct
50 Correct 207 ms 32888 KB Output is correct
51 Correct 213 ms 32888 KB Output is correct
52 Correct 211 ms 32888 KB Output is correct
53 Correct 208 ms 33016 KB Output is correct
54 Correct 225 ms 35192 KB Output is correct
55 Correct 177 ms 32504 KB Output is correct
56 Correct 225 ms 35828 KB Output is correct
57 Correct 1710 ms 131384 KB Output is correct
58 Correct 1686 ms 131448 KB Output is correct
59 Correct 1566 ms 131276 KB Output is correct
60 Correct 1602 ms 131316 KB Output is correct
61 Correct 1581 ms 131132 KB Output is correct
62 Correct 1597 ms 131204 KB Output is correct
63 Correct 1098 ms 96780 KB Output is correct
64 Correct 1083 ms 96884 KB Output is correct
65 Correct 1108 ms 98548 KB Output is correct
66 Correct 1133 ms 98748 KB Output is correct
67 Correct 1159 ms 98548 KB Output is correct
68 Correct 1161 ms 98668 KB Output is correct
69 Correct 1119 ms 98668 KB Output is correct
70 Correct 1127 ms 98716 KB Output is correct
71 Correct 1181 ms 98668 KB Output is correct
72 Correct 1148 ms 98668 KB Output is correct
73 Correct 1079 ms 92016 KB Output is correct
74 Correct 1091 ms 79352 KB Output is correct
75 Correct 1060 ms 91764 KB Output is correct
76 Correct 1076 ms 95176 KB Output is correct
77 Correct 1060 ms 95200 KB Output is correct
78 Correct 1160 ms 103408 KB Output is correct
79 Correct 829 ms 82884 KB Output is correct
80 Correct 1285 ms 105184 KB Output is correct